On 2015-01-29 09:43, Stefan G. Weichinger wrote:
sorry ... still a bit OT but maybe interesting for others as well:


Yesterday I started to modify the following ansible role to fit my needs
and work with gentoo target hosts:

https://github.com/debops/ansible-dhcpd

I modified tasks/main.yml (use portage ... install iproute2 as well) and
edited defaults/main.yml to reflect the environment of site A at first.


my first testing playbook:

---
- hosts: site-A-dhcpd
  user: root
  roles:
    - ansible-dhcpd

Now I wonder how to use the same role for configuring site B.

defaults/main.yml currently contains the config (vars ... yes) for site
A ...

A copy of the role is way too redundant ...

What is the/a correct and elegant way to do that?

Have a defaults/site-B.conf.yml or something and include that in a 2nd
playbook?

Use some file in the vars/ directory ... ?


I am quite sure that this is just a beginner's problem ... but in these
days my brain is a bit exhausted by my current workload etc

Thanks for any hints, Stefan!

Have your IPs listed in hosts-production.

For each site create a file, like:

site_A.yml
- hosts: site_A
  roles:
    - ...

site_B.yml
- hosts: site_B
  roles:
    - ...

Then create site.yml where you include site_A.yml and site_B.yml. Mostly, you will not only use roles inclusion, but have something special done on the server, so either you create a role corresponding to this file (like role site_A, site_B) where you name the tasks or you put it directly in the site_A.yml, site_B.yml file. This is the stuff unique to the server, like creating a specific user, specific directory, with specific files...

Then if you want to reconfigure all, just
ansible-playbook -i hosts-production site.yml

Only site_A:
ansible-playbook -i hosts-production site_A.yml

Only configure postfix on site_B:
ansible-playbook -i hosts-production site_B.yml --tags postfix -v

Read:
http://docs.ansible.com/playbooks_roles.html
http://docs.ansible.com/playbooks_best_practices.html

Reply via email to