On Tuesday, 6 March 2018 11.49.30 CET Marcos Georgopoulos wrote:
>
> Hi, I am trying to work out how to iterate through some results from a
> command I am running on a network device. the idea is when I find the line
> that matches what I am looking for based on a regexp I want to store it.
>
>
>
>
> tasks:
>
> - name: get the existing access-list
> ios_command:
> provider: "{{ cli }}"
> commands:
> - show access-list mgtaccess
> register: result
>
> - debug: var=result.stdout_lines
>
> - name: Do something with each result
> debug:
> msg: "{{ item }}"
> with_items:
> - "{{ result.stdout_lines }}"
>
>
>
> This is the output from the task
>
>
>
>
>
> ok: [172.16.1.135] => (item=[u'Standard IP access list mgtaccess', u' 20
> permit 10.1.1.1', u' 10 permit 192.168.0.1', u' 30 permit any (2566
> matches)']) => {
> "changed": false,
> "failed": false,
> "item": [
> "Standard IP access list mgtaccess",
> " 20 permit 10.1.1.1",
> " 10 permit 192.168.0.1",
> " 30 permit any (2566 matches)"
> ],
>
>
> "msg": [
> "Standard IP access list mgtaccess",
> " 20 permit 10.1.1.1",
> " 10 permit 192.168.0.1",
> " 30 permit any (2566 matches)"
>
> ]
> }
>
>
> I'm confused shouldn't I be seeing multiple individual 'msg's??
result.stdout_lines is a list that contains lists
So you have result.stdout_lines.0.0 the first line, result.stdout_lines.0.1 the
second one and so on.
You can do
with_items: '{{ result.stdout_lines.0 }}'
to get what you are after.
--
Kai Stian Olstad
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/6949327.BaRiD72d7I%40x1.
For more options, visit https://groups.google.com/d/optout.