Hi Guys,

I'd expect the following to work, 

I issue the show run snmp | inc host | inc traps command.  I get the 
returned values , now I just want to loop through the returned 
configuration lines and send them back to the router with no in front of 
them.  It seems to generate the proper output, if I manually take the 
command and issue it on the router it works - why is this failing ?

---
  - name: Update the SNMP information on the network
    hosts: lab
    gather_facts: no 
    connection: local

    vars:
      ios_provider:
        username: "{{ user }}"
        password: "{{ password }}"
        host: "{{ inventory_hostname }}"
    
      snmp:
        new_hosts:
          - 1.1.1.1
          - 2.2.2.2
        community: xxxxxx
        version: 2c
        vrf: management
        src_inf: mgmt

    tasks:
      #- name: generate snmp host configurations
      #  template: src=snmp_update.j2 dest=configs/snmp_auto_update.cfg

      - name: get current snmp hosts
        register: command_output
        ios_command:
          commands: "show run snmp | inc host | inc traps"
          provider: "{{ ios_provider }}"

      - name: delete current snmp hosts
        ios_command:
          commands:
            - no {{item}}
          provider: "{{ios_provider}}"
        with_items: "{{ command_output.stdout_lines }}"

      - debug: msg="{{'no ' + item}}"
        with_items: "{{command_output.stdout_lines}}"




Using /home/gmckee/ansible/ansible.cfg as config file
 ____________________________
< PLAYBOOK: snmp_update.yaml >
 ----------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

1 plays in snmp_update.yaml
 ___________________________________________________
< PLAY [Update the SNMP information on the network] >
 ---------------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

META: ran handlers
 _______________________________
< TASK [get current snmp hosts] >
 -------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

task path: /home/gmckee/ansible/snmp_update.yaml:28
<10.70.253.249> using connection plugin network_cli
Using module file 
/usr/lib/python2.6/site-packages/ansible/modules/network/ios/ios_command.py
<10.70.253.249> ESTABLISH LOCAL CONNECTION FOR USER: gmckee
<10.70.253.249> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo 
/tmp/.ansible-${USER}/tmp/ansible-tmp-1500556542.83-249131789769820 `" && 
echo ansible-tmp-1500556542.83-249131789769820="` echo 
/tmp/.ansible-${USER}/tmp/ansible-tmp-1500556542.83-249131789769820 `" ) && 
sleep 0'
<10.70.253.249> PUT /tmp/tmp5vpjgn TO 
/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556542.83-249131789769820/ios_command.py
<10.70.253.249> EXEC /bin/sh -c 'chmod u+x 
/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556542.83-249131789769820/ 
/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556542.83-249131789769820/ios_command.py
 
&& sleep 0'
<10.70.253.249> EXEC /bin/sh -c '/usr/bin/python 
/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556542.83-249131789769820/ios_command.py;
 
rm -rf 
"/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556542.83-249131789769820/" > 
/dev/null 2>&1 && sleep 0'
ok: [10.70.253.249] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "auth_pass": null,
            "authorize": null,
            "commands": [
                "show run snmp | inc host | inc traps"
            ],
            "host": null,
            "interval": 1,
            "match": "all",
            "password": null,
            "port": null,
            "provider": {
                "auth_pass": null,
                "authorize": null,
                "host": "10.70.253.249",
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "port": null,
                "ssh_keyfile": null,
                "timeout": null,
                "username": "gmckee"
            },
            "retries": 10,
            "ssh_keyfile": null,
            "timeout": null,
            "username": null,
            "wait_for": null
        }
    },
    "stdout": [
        "snmp-server host 1.1.1.1 traps version 2c test"
    ],
    "stdout_lines": [
        [
            "snmp-server host 1.1.1.1 traps version 2c test"
        ]
    ]
}
 __________________________________
< TASK [delete current snmp hosts] >
 ----------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

task path: /home/gmckee/ansible/snmp_update.yaml:34
<10.70.253.249> using connection plugin network_cli
Using module file 
/usr/lib/python2.6/site-packages/ansible/modules/network/ios/ios_command.py
<10.70.253.249> ESTABLISH LOCAL CONNECTION FOR USER: gmckee
<10.70.253.249> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo 
/tmp/.ansible-${USER}/tmp/ansible-tmp-1500556543.8-254349033852038 `" && 
echo ansible-tmp-1500556543.8-254349033852038="` echo 
/tmp/.ansible-${USER}/tmp/ansible-tmp-1500556543.8-254349033852038 `" ) && 
sleep 0'
<10.70.253.249> PUT /tmp/tmp5vpjgn TO 
/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556543.8-254349033852038/ios_command.py
<10.70.253.249> EXEC /bin/sh -c 'chmod u+x 
/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556543.8-254349033852038/ 
/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556543.8-254349033852038/ios_command.py
 
&& sleep 0'
<10.70.253.249> EXEC /bin/sh -c '/usr/bin/python 
/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556543.8-254349033852038/ios_command.py;
 
rm -rf "/tmp/.ansible-gmckee/tmp/ansible-tmp-1500556543.8-254349033852038/" 
> /dev/null 2>&1 && sleep 0'
ok: [10.70.253.249] => (item=snmp-server host 1.1.1.1 traps version 2c 
test) => {
    "changed": false,
    "invocation": {
        "module_args": {
            "auth_pass": null,
            "authorize": null,
            "commands": [
                "no snmp-server host 1.1.1.1 traps version 2c test"
            ],
            "host": null,
            "interval": 1,
            "match": "all",
            "password": null,
            "port": null,
            "provider": {
                "auth_pass": null,
                "authorize": null,
                "host": "10.70.253.249",
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "port": null,
                "ssh_keyfile": null,
                "timeout": null,
                "username": "gmckee"
            },
            "retries": 10,
            "ssh_keyfile": null,
            "timeout": null,
            "username": null,
            "wait_for": null
        }
    },
    "item": "snmp-server host 1.1.1.1 traps version 2c test",
    "stdout": [
        "^\n% Invalid command at '^' marker."
    ],
    "stdout_lines": [
        [
            "^",
            "% Invalid command at '^' marker."
        ]
    ]
}
 ______________
< TASK [debug] >
 --------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

task path: /home/gmckee/ansible/snmp_update.yaml:41
ok: [10.70.253.249] => (item=snmp-server host 1.1.1.1 traps version 2c 
test) => {
    "item": "snmp-server host 1.1.1.1 traps version 2c test",
    "msg": "no snmp-server host 1.1.1.1 traps version 2c test"
}
META: ran handlers
META: ran handlers
 ____________
< PLAY RECAP >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

10.70.253.249              : ok=3    changed=0    unreachable=0    failed=0

-- 
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/80543e7c-4611-4d05-b94d-acebb23ff6f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to