On Thu, 2 Jul 2020 13:59:13 +0530 "T. JENISHA" <[email protected]> wrote:
> - name: Ex grep
> gather_facts: yes
> hosts: localhost
> connection: local
> tasks:
>
> - name: Run ag_diag_comm
> command: cat "ag_diag.txt"
> register: ag_diag
>
> - 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
>
> fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an
> > 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
Fix the indentation. I've put the dots '.' into the code to make the
comparison easier. In addition to this, use your registered data in the loop
loop: "{{ ag_diag.stdout_lines|
For your convenience the code is also here
https://gist.github.com/vbotka/1e68ef07627dc37b252553b6d838ed20
--
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/20200702112417.0974f64d%40gmail.com.
pgpAo2m1blNnq.pgp
Description: OpenPGP digital signature
