On 22. aug. 2016 12:10, 'Steve Kersley' via Ansible Project wrote:
This works fine, but it fails on a switch that has no current value set, so I used a 'when' clause to check if stdout from the collection task is empty. However, this isn't working. If I print via debug the value of stdout, it certainly looks empty so why isn't the when clause working?Any help on what I'm doing wrong (or a better way to do it) appreciated? For the moment I can kludge around it by setting a value before I delete all the values, so that I know it should always have something and not worry about it, but that's bad practice and I'd prefer to know what I'm doing wrong for next time! - hosts: switches gather_facts: False vars: cli: host: "{{ inventory_hostname }}" username: user password: password auth_pass: password transport: cli tasks: - name: Collect logging configuration connection: local become: false register: syslog ios_command: provider: "{{ cli }}" authorize: yes commands: - show running-config | include logging host - debug: msg="empty" when: syslog.stdout == "" - debug: msg="not empty" when: syslog.stdout != "" - debug: var=syslog.stdout - name: Remove existing syslog config connection: local become: false when: syslog.stdout != "" ios_command: provider: "{{ cli }}" authorize: yes commands: - configure terminal - no {{ item }} - exit with_items: "{{ syslog.stdout_lines }}" Output: PLAY [switches] **************************************************************** TASK [Collect logging configuration] ******************************************* ok: [switchname] TASK [debug] ******************************************************************* skipping: [switchname] TASK [debug] ******************************************************************* ok: [switchname] => { "msg": "not empty" } TASK [debug] ******************************************************************* ok: [switchname] => { "syslog.stdout": [ "" ] }
It's not empty, it does contain a list. So if you do this I think it should work when: syslog.stdout[0] != "" -- 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/f2430ec1-b76c-aead-987a-dbabc16f97cf%40olstad.com. For more options, visit https://groups.google.com/d/optout.
