Hello,
I have a common.yml playbook which manage all the system default ( resolv.conf, snmp, ntp…) which must be call for all servers so the code look like this :
---
- name: Commons conf
hosts: all
gather_facts: true
roles:
- apt
- resolv
- snmpd
- ntpd
this playbook works well.
When I create a VM in my workflow, I create a new playbook which needs to include the common.yml playbook and include custom config with new roles for this server. This will define the full state of the VM ensuring we don’t rewrite code or forget to include sorole each time.
This is my issue here, I don’t find a clean way to create a playbook which doesn’t need to use --limit option to only apply to the selected target.
For the following code I need to use --limit to avoid commons-playbook to be executed on all target.
---
- name: Run commons-playbook first
import_playbook: commons-playbook.yml
- name: Install and Configure
hosts: nagios
gather_facts: true
roles:
- nagios
- php
So I tried to define a variable with the hostname and to provide this variable to host field, but I didn’t manage to make it work :
---
- name: Playbook for specific servers
hosts: localhost
vars:
target_hosts:
- server1
- server2
- name: Nodejs install and configuration
hosts: "{{ target_host }}"
gather_facts: true
import_playbook: common.yml
- name: Nodejs install and configuration
hosts: "{{ target_host }}"
gather_facts: true
roles:
- php
- webserver
Any help appreciated !