Hello Folks,
Trying to do a basic example for roles for generating configs. I cannot get
to pass the variable to the tasks. Any help is appreciated.
$ ansible --version
ansible 2.4.2.0
config file = /home/cisco/ansible.cfg
configured module search path = [u'/home/cisco/.ansible/plugins/modules',
u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0
20160609]
$ more roles/router/tasks/main.yml
---
- name: generate configuration files
template: src=router.j2
dest=/home/cisco/ansible/cfgs/{{item.hostname}}.txt
with_items: " {{ routers }}"
$ more roles/router/vars/mail.yml
---
routers:
- { hostname: router-rtr1 }
- { hostname: router-rtr2 }
- { hostname: router-rtr3 }
- { hostname: router-rtr4 }
- { hostname: router-rtr5 }
- { hostname: router-rtr6 }
...
$ ansible-playbook config-gen.yml
PLAY [Generate router configuration files]
****************************************************
TASK [Gathering Facts]
************************************************************************
ok: [localhost]
*TASK [router : generate configuration files]
***************************************************
*fatal: [localhost]: FAILED! => {"msg": "'routers' is undefined"}*
PLAY RECAP
************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1
$
$ tree
.
├── ansible
│ └── cfgs
│ ├── router-rtr1.txt
│ └── router-rtr2.txt
├── ansible.cfg
├── config-gen.retry
├── config-gen.yml
├── hosts
├── np-perf-playbook-v2.1.yml
├── np-perf-playbook-v2.retry
├── np-perf-playbook-v2.yml
├── playbook-v3.retry
├── playbook-v3.yml
├── roles
│ └── router
│ ├── tasks
│ │ └── main.yml
│ ├── templates
│ │ └── router.j2
│ └── vars
│ └── mail.yml
├── site.retry
├── site.yml
├── sr_playbook-v1.yml
├── test.txt
└── test.yml
Thanks,
Yogi
--
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/c2bdb39c-12bf-440e-8e68-7a8941c7d24a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.