All you need is to use is slicing with a step:
If my variable is `verylongvariable: s1i2v3e4l5`
If I want `sivel`, I'd use: {{verylongvariable[::2]}}
If I want `12345`, I'd use: {{verylongvariable[1::2]}}
On Tue, Sep 12, 2023 at 8:35 AM Kathy L <[email protected]> wrote:
> I am trying to grab every other character in a very long variable, and
> placing it in another variable. This is what I have:
>
> set_fact:
> new_string: "{{ [ 0,2,4,6,8,10,12 ] | map('extract', verylongvariable)
> }}"
>
> I've also tried this:
> set_fact:
> new_string: "{{ [ 0,2,4,6,8,10,12 ] | map('extract', verylongvariable)
> }} | map('join', ',' | join('')) }}
>
> What I end up getting in the new_string is this:
>
> 'N', 'y', 'a', 'd'....
>
> What I want is:
>
> Nyad....
>
> I clearly am not understanding the join syntax. How do I use join to get
> the new variable?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ec75223e-8d4a-4aa8-bbfa-2d78389d35fan%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/ec75223e-8d4a-4aa8-bbfa-2d78389d35fan%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
Matt Martz
@sivel
sivel.net
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAD8N0v9nx3t386u4LUMDojNxt1mkDy77eJZ_F3T01VP3ie87pw%40mail.gmail.com.