include not resolving variables

27 views
Skip to first unread message

Pujan Shah

unread,
Aug 14, 2015, 8:59:12 AM8/14/15
to Ansible Project
Hi,

I want to use include in a way that every host get's different playbook.

This is important for me as I have some tasks that are specific to each host.

I can create a custom role where I keep all "semi-manual" and use once stuff related to all hosts in somthing like host_a.yml host_b.yml host_c.yml and than in main playbook I can call include host_{{ inventory_hostname }}.yml

This way all my semi-manual and host specific things are also part of my whole setup.

I am not sure if this is possible right now or not but from looking at https://github.com/ansible/ansible/issues/5424 I think it's not possible.

I can do include_vars this way but not simple include.

Can someone suggest better alternative if this is not possible?

Regards
Pujan

Ivan Voras

unread,
Aug 14, 2015, 9:44:13 AM8/14/15
to Ansible Project
Do you really need variables in includes?

I have something similar, a file named cluster.yml which only includes other files:

---
- include: webservers.yml
- include: dbservers.yml

and each of those files has, e.g.

---
- hosts: webservers
  roles: 
   - web
   - cache

---
- hosts: dbservers
  roles:
    - db

And each of the roles, db and web, have a dependency (http://docs.ansible.com/ansible/playbooks_roles.html#role-dependencies) on a role called "common" which installs generic packages and has handlers such as "restart syslog".

Pujan Shah

unread,
Aug 14, 2015, 10:27:38 AM8/14/15
to Ansible Project

In inventory I have a, b and c. Now I want to create user x on a delete file y from b and create file z on c. This is not part of role but let's say users's requirement. To do so I can create a role called custom which contains
---
- include: {{ inventory_hostname }}.yml

and then create a.yml, b.yml and c.yml with respective tasks.

This way all my changes are "documented" in my ansible git repo and I don't have to customize systems outside the scope of roles.
Reply all
Reply to author
Forward
0 new messages