Gentoo Archives: gentoo-user

From: Tomas Mozes <tomas.mozes@××××.sk>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Usign ansible
Date: Thu, 29 Jan 2015 09:47:57
Message-Id: 757eece3b42b3a715fe9c4e5478cba76@shmu.sk
In Reply to: Re: [gentoo-user] Usign ansible by "Stefan G. Weichinger"
1 On 2015-01-29 09:43, Stefan G. Weichinger wrote:
2 > sorry ... still a bit OT but maybe interesting for others as well:
3 >
4 >
5 > Yesterday I started to modify the following ansible role to fit my
6 > needs
7 > and work with gentoo target hosts:
8 >
9 > https://github.com/debops/ansible-dhcpd
10 >
11 > I modified tasks/main.yml (use portage ... install iproute2 as well)
12 > and
13 > edited defaults/main.yml to reflect the environment of site A at first.
14 >
15 >
16 > my first testing playbook:
17 >
18 > ---
19 > - hosts: site-A-dhcpd
20 > user: root
21 > roles:
22 > - ansible-dhcpd
23 >
24 > Now I wonder how to use the same role for configuring site B.
25 >
26 > defaults/main.yml currently contains the config (vars ... yes) for site
27 > A ...
28 >
29 > A copy of the role is way too redundant ...
30 >
31 > What is the/a correct and elegant way to do that?
32 >
33 > Have a defaults/site-B.conf.yml or something and include that in a 2nd
34 > playbook?
35 >
36 > Use some file in the vars/ directory ... ?
37 >
38 >
39 > I am quite sure that this is just a beginner's problem ... but in these
40 > days my brain is a bit exhausted by my current workload etc
41 >
42 > Thanks for any hints, Stefan!
43
44 Have your IPs listed in hosts-production.
45
46 For each site create a file, like:
47
48 site_A.yml
49 - hosts: site_A
50 roles:
51 - ...
52
53 site_B.yml
54 - hosts: site_B
55 roles:
56 - ...
57
58 Then create site.yml where you include site_A.yml and site_B.yml.
59 Mostly, you will not only use roles inclusion, but have something
60 special done on the server, so either you create a role corresponding to
61 this file (like role site_A, site_B) where you name the tasks or you put
62 it directly in the site_A.yml, site_B.yml file. This is the stuff unique
63 to the server, like creating a specific user, specific directory, with
64 specific files...
65
66 Then if you want to reconfigure all, just
67 ansible-playbook -i hosts-production site.yml
68
69 Only site_A:
70 ansible-playbook -i hosts-production site_A.yml
71
72 Only configure postfix on site_B:
73 ansible-playbook -i hosts-production site_B.yml --tags postfix -v
74
75 Read:
76 http://docs.ansible.com/playbooks_roles.html
77 http://docs.ansible.com/playbooks_best_practices.html

Replies

Subject Author
Re: [gentoo-user] Usign ansible "Stefan G. Weichinger" <lists@×××××.at>