]>
Commit | Line | Data |
---|---|---|
109c6b75 LSJ |
1 | --- |
2 | - hosts: all | |
3 | remote_user: vagrant | |
4 | become: true | |
5 | vars: | |
6 | - host_vars_directory: './host_vars' | |
7 | - host_vars_file: '{{ host_vars_directory }}/{{ inventory_hostname }}.yml' | |
8 | - pri_domain_name: 'vagrant.local' | |
9 | - ssh_key_path: '.vagrant/machines/{{ inventory_hostname }}/virtualbox/private_key' | |
10 | - update_host_vars: true | |
11 | roles: | |
12 | tasks: | |
13 | - name: updating apt cache (Debian) | |
14 | apt: | |
15 | update_cache: yes | |
16 | cache_valid_time: 3600 | |
17 | when: ansible_os_family == "Debian" | |
18 | ||
19 | - name: installing ansible pre-reqs (Debian) | |
20 | apt: | |
21 | name: "{{ item }}" | |
22 | state: present | |
23 | with_items: | |
24 | - python-dev | |
25 | - python-pip | |
26 | when: ansible_os_family == "Debian" | |
27 | ||
28 | - name: installing epel repo (RedHat) | |
29 | yum: | |
30 | name: "epel-release" | |
31 | state: present | |
32 | when: > | |
33 | ansible_os_family == "RedHat" and | |
34 | ansible_distribution != "Fedora" | |
35 | ||
36 | - name: installing ansible pre-reqs (RedHat) | |
37 | yum: | |
38 | name: "{{ item }}" | |
39 | state: present | |
40 | with_items: | |
41 | - python-devel | |
42 | - python-dnf | |
43 | - python-pip | |
44 | when: > | |
45 | ansible_os_family == "RedHat" and | |
46 | ansible_distribution != "Fedora" | |
47 | ||
48 | - name: installing ansible pre-reqs (Fedora) | |
49 | dnf: | |
50 | name: "{{ item }}" | |
51 | state: present | |
52 | with_items: | |
53 | - gmp-devel | |
54 | - python-crypto | |
55 | - python-devel | |
56 | - python-dnf | |
57 | - python-pip | |
58 | when: > | |
59 | ansible_os_family == "RedHat" and | |
60 | ansible_distribution == "Fedora" | |
61 | ||
62 | - name: installing ansible | |
63 | pip: | |
64 | name: "ansible" | |
65 | state: present | |
66 | ||
67 | - name: ensuring host_vars directory exists | |
68 | file: | |
69 | path: "./host_vars" | |
70 | state: directory | |
71 | delegate_to: localhost | |
72 | run_once: true | |
73 | become: false | |
74 | when: update_host_vars is defined and update_host_vars | |
75 | ||
76 | - name: ensuring host file exists in host_vars | |
77 | stat: | |
78 | path: "{{ host_vars_file }}" | |
79 | delegate_to: localhost | |
80 | register: host_var | |
81 | become: false | |
82 | when: > | |
83 | update_host_vars is defined and | |
84 | update_host_vars | |
85 | ||
86 | - name: creating missing host_vars | |
87 | file: | |
88 | path: "{{ host_vars_file }}" | |
89 | state: touch | |
90 | delegate_to: localhost | |
91 | become: false | |
92 | when: not host_var.stat.exists | |
93 | ||
94 | - name: updating ansible_ssh_port | |
95 | lineinfile: | |
96 | dest: "{{ host_vars_file }}" | |
97 | regexp: "^ansible_ssh_port{{ ':' }}" | |
98 | line: "ansible_ssh_port{{ ':' }} 22" | |
99 | delegate_to: localhost | |
100 | become: false | |
101 | when: > | |
102 | (update_host_vars is defined and | |
103 | update_host_vars) and | |
104 | (ansible_eth1 is defined or | |
105 | ansible_enp0s8 is defined) | |
106 | ||
107 | - name: updating ansible_ssh_host | |
108 | lineinfile: | |
109 | dest: "{{ host_vars_file }}" | |
110 | regexp: "^ansible_ssh_host{{ ':' }}" | |
111 | line: "ansible_ssh_host{{ ':' }} {{ ansible_eth1.ipv4.address }}" | |
112 | delegate_to: localhost | |
113 | become: false | |
114 | when: > | |
115 | (update_host_vars is defined and | |
116 | update_host_vars) and | |
117 | ansible_eth1 is defined | |
118 | ||
119 | - name: updating ansible_ssh_host | |
120 | lineinfile: | |
121 | dest: "{{ host_vars_file }}" | |
122 | regexp: "^ansible_ssh_host{{ ':' }}" | |
123 | line: "ansible_ssh_host{{ ':' }} {{ ansible_enp0s8.ipv4.address }}" | |
124 | delegate_to: localhost | |
125 | become: false | |
126 | when: > | |
127 | (update_host_vars is defined and | |
128 | update_host_vars) and | |
129 | ansible_enp0s8 is defined | |
130 | ||
131 | - name: updating ansible_ssh_key | |
132 | lineinfile: | |
133 | dest: "{{ host_vars_file }}" | |
134 | regexp: "^ansible_ssh_private_key_file{{ ':' }}" | |
135 | line: "ansible_ssh_private_key_file{{ ':' }} {{ ssh_key_path }}" | |
136 | delegate_to: localhost | |
137 | become: false | |
138 | when: > | |
139 | update_host_vars is defined and | |
140 | update_host_vars | |
141 | ||
142 | - name: ensuring host_vars is yaml formatted | |
143 | lineinfile: | |
144 | dest: "{{ host_vars_file }}" | |
145 | regexp: "---" | |
146 | line: "---" | |
147 | insertbefore: BOF | |
148 | delegate_to: localhost | |
149 | become: false | |
150 | when: > | |
151 | update_host_vars is defined and | |
152 | update_host_vars |