Hi!

On Thu, 2 Jul 2020 10:24:29 +0530
"T. JENISHA" <[email protected]> wrote:

> my_data is input data stored in the register

If you have problem test the code with simple data first. For example

  vars:
    my_data: |
      a: 1
      b: 2


> whats my_key?

It's variable. See https://docs.python.org/3/library/re.html

> fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an
> undefined variable. The error was: 'my_key' is undefined\n\nThe error
> appears to be in
> '/home/jenisha/PycharmProjects/ansible_ex/tasks/grep_ex.yml': line 31,

Fix it. The code below works as expected. Mind the indentation.

> >     - set_fact:
> >         my_agent: "{{ my_agent|default({})|
> >                       combine({my_key: my_val}) }}"
> >       loop: "{{ my_data.splitlines()|
> >                 select('match', my_regex)|
> >                 list }}"
> >       vars:
> >         my_regex: '^(.*?):(.*)$'
> >         my_key: "{{ item|
> >                     regex_replace(my_regex, '\\1')|
> >                     trim|
> >                     regex_replace(' ', '_') }}"
> >         my_val: "{{ item|
> >                     regex_replace(my_regex, '\\2')|
> >                     trim }}"
> >     - debug:
> >         var: my_agent
> >     - debug:
> >         var: my_agent.Logical_Agent_Name

-- 
Vladimir Botka

-- 
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/20200702073841.4aaa0021%40gmail.com.

Attachment: pgpyvF3aXCeFo.pgp
Description: OpenPGP digital signature

Reply via email to