Ansible playbook only run against one host
root@osboxes:~/ansible_project/second_p# cat conditionals_3.yml
---
- name: show hostname
hosts: ios-devices
connection: local
tasks:
- name: show hostname
ios_command:
commands: "show run | in hostname"
register: output
- debug:
var: output
- name: pause with render
pause:
prompt: "{{lookup('template', 'conditional.j2')}}"
root@osboxes:~/ansible_project/second_p# cat conditional.j2
output = {{output}}
{% if "las-a" in output.stdout[0]%}
I am "las-a"
{%else%}
I am "las-b"
{%endif%}
root@osboxes:~/ansible_project/second_p# cat hosts
# Ansile hosts file for lab
[all:vars]
ansible_user=xxx
ansible_ssh_pass=xxx
[ios-devices]
las-a
las-b
The actual output is
TASK [pasuse with render] ************************************************************************************* [pasuse with render] output = {'failed': False, u'changed': False, u'stdout_lines': [[u'hostname las-a', u'logging origin-id hostname']], u'stdout': [u'hostname las-a\nlogging origin-id hostname']}
I am "las-a" : ok: [las-a]
PLAY RECAP ****************************************************************************************************
las-a : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
las-b : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
But I want I am "las-a" and I am "las-b"