|
1 | 1 |
|
2 | 2 | - hosts: all |
3 | | - vars_files: |
4 | | - - shared_vars.yml |
5 | 3 | strategy: linear |
6 | 4 | gather_facts: false |
7 | 5 | tasks: |
8 | | - - raw: > |
9 | | - if ! python -c ''; then |
10 | | - if type -p yum; then |
11 | | - yum -y install python; |
12 | | - else |
13 | | - apt-get -y update && apt-get -y install python; |
14 | | - fi; |
| 6 | + - name: Install bootstrap packages |
| 7 | + raw: | |
| 8 | + set -o errexit |
| 9 | + set -o nounset |
| 10 | + if type -p yum; then |
| 11 | + yum -y install {{ bootstrap_packages | join(' ') }} |
| 12 | + else |
| 13 | + apt-get -y update |
| 14 | + apt-get -y --no-install-recommends install {{ bootstrap_packages | join(' ') }} |
15 | 15 | fi |
| 16 | + when: bootstrap_packages | length |
16 | 17 |
|
17 | 18 | - hosts: all |
18 | | - vars_files: |
19 | | - - shared_vars.yml |
20 | 19 | strategy: mitogen_free |
| 20 | + # Resource limitation, my laptop freezes doing every container concurrently |
| 21 | + serial: 4 |
21 | 22 | # Can't gather facts before here. |
22 | 23 | gather_facts: true |
23 | 24 | vars: |
24 | 25 | distro: "{{ansible_distribution}}" |
25 | | - ver: "{{ansible_distribution_major_version}}" |
26 | | - |
27 | | - packages: |
28 | | - common: |
29 | | - - openssh-server |
30 | | - - rsync |
31 | | - - strace |
32 | | - - sudo |
33 | | - Debian: |
34 | | - "9": |
35 | | - - libjson-perl |
36 | | - - python-virtualenv |
37 | | - - locales |
38 | | - CentOS: |
39 | | - "5": |
40 | | - - perl |
41 | | - - sudo |
42 | | - #- perl-JSON -- skipped on CentOS 5, packages are a pain. |
43 | | - "6": |
44 | | - - perl-JSON |
45 | | - "7": |
46 | | - - perl-JSON |
47 | | - - python-virtualenv |
48 | | - |
49 | 26 | tasks: |
50 | 27 | - when: ansible_virtualization_type != "docker" |
51 | 28 | meta: end_play |
52 | 29 |
|
53 | | - - name: Ensure requisite Debian packages are installed |
| 30 | + - name: Ensure requisite apt packages are installed |
54 | 31 | apt: |
55 | | - name: "{{packages.common + packages[distro][ver]}}" |
56 | | - state: installed |
| 32 | + name: "{{ common_packages + packages }}" |
| 33 | + state: present |
| 34 | + install_recommends: false |
57 | 35 | update_cache: true |
58 | | - when: distro == "Debian" |
| 36 | + when: ansible_pkg_mgr == 'apt' |
59 | 37 |
|
60 | | - - name: Ensure requisite Red Hat packaed are installed |
| 38 | + - name: Ensure requisite yum packages are installed |
61 | 39 | yum: |
62 | | - name: "{{packages.common + packages[distro][ver]}}" |
63 | | - state: installed |
| 40 | + name: "{{ common_packages + packages }}" |
| 41 | + state: present |
64 | 42 | update_cache: true |
65 | | - when: distro == "CentOS" |
| 43 | + when: ansible_pkg_mgr == 'yum' |
66 | 44 |
|
67 | | - - name: Clean up apt cache |
68 | | - command: apt-get clean |
69 | | - when: distro == "Debian" |
| 45 | + - name: Ensure requisite dnf packages are installed |
| 46 | + dnf: |
| 47 | + name: "{{ common_packages + packages }}" |
| 48 | + state: present |
| 49 | + update_cache: true |
| 50 | + when: ansible_pkg_mgr == 'dnf' |
| 51 | + |
| 52 | + - name: Clean up package cache |
| 53 | + vars: |
| 54 | + clean_command: |
| 55 | + apt: apt-get clean |
| 56 | + yum: yum clean all |
| 57 | + dnf: dnf clean all |
| 58 | + command: "{{ clean_command[ansible_pkg_mgr] }}" |
| 59 | + args: |
| 60 | + warn: false |
70 | 61 |
|
71 | 62 | - name: Clean up apt package lists |
72 | 63 | shell: rm -rf {{item}}/* |
73 | 64 | with_items: |
74 | 65 | - /var/cache/apt |
75 | 66 | - /var/lib/apt/lists |
76 | | - when: distro == "Debian" |
| 67 | + when: ansible_pkg_mgr == 'apt' |
77 | 68 |
|
78 | | - - name: Clean up yum cache |
79 | | - command: yum clean all |
80 | | - when: distro == "CentOS" |
| 69 | + - name: Configure /usr/bin/python |
| 70 | + command: alternatives --set python /usr/bin/python3.8 |
| 71 | + args: |
| 72 | + creates: /usr/bin/python |
| 73 | + when: inventory_hostname in ["centos8"] |
81 | 74 |
|
82 | 75 | - name: Enable UTF-8 locale on Debian |
83 | 76 | copy: |
84 | 77 | dest: /etc/locale.gen |
85 | 78 | content: | |
86 | 79 | en_US.UTF-8 UTF-8 |
87 | 80 | fr_FR.UTF-8 UTF-8 |
88 | | - when: distro == "Debian" |
| 81 | + when: ansible_pkg_mgr == 'apt' |
89 | 82 |
|
90 | 83 | - name: Generate UTF-8 locale on Debian |
91 | 84 | shell: locale-gen |
92 | | - when: distro == "Debian" |
| 85 | + when: ansible_pkg_mgr == 'apt' |
93 | 86 |
|
94 | 87 | - name: Write Unicode into /etc/environment |
95 | 88 | copy: |
|
115 | 108 | permit :mitogen__group |
116 | 109 | permit :root |
117 | 110 |
|
118 | | - - name: Vanilla Ansible needs simplejson on CentOS 5. |
119 | | - shell: mkdir -p /usr/lib/python2.4/site-packages/simplejson/ |
120 | | - when: distro == "CentOS" and ver == "5" |
121 | | - |
122 | | - - name: Vanilla Ansible needs simplejson on CentOS 5. |
123 | | - synchronize: |
124 | | - dest: /usr/lib/python2.4/site-packages/simplejson/ |
125 | | - src: ../../ansible_mitogen/compat/simplejson/ |
126 | | - when: distro == "CentOS" and ver == "5" |
127 | | - |
128 | 111 | - name: Set root user password and shell |
129 | 112 | user: |
130 | 113 | name: root |
|
182 | 165 | - name: Install CentOS wheel sudo rule |
183 | 166 | lineinfile: |
184 | 167 | path: /etc/sudoers |
185 | | - line: "%wheel ALL=(ALL) ALL" |
186 | | - when: distro == "CentOS" |
| 168 | + regexp: '#* *%wheel +ALL=(ALL) +ALL' |
| 169 | + line: "%wheel ALL=(ALL) ALL" |
| 170 | + when: ansible_os_family == 'RedHat' |
187 | 171 |
|
188 | 172 | - name: Enable SSH banner |
189 | 173 | lineinfile: |
|
202 | 186 | regexp: '.*session.*required.*pam_loginuid.so' |
203 | 187 | line: session optional pam_loginuid.so |
204 | 188 |
|
| 189 | + # Normally this would be removed by systemd-networkd-wait-online. If |
| 190 | + # present ssh works only for root. The message displayed is |
| 191 | + # > System is booting up. Unprivileged users are not permitted to log in |
| 192 | + # > yet. Please come back later. For technical details, see pam_nologin(8). |
| 193 | + - name: Remove login lockout |
| 194 | + file: |
| 195 | + path: /run/nologin |
| 196 | + state: absent |
| 197 | + |
205 | 198 | - name: Install convenience script for running an straced Python |
206 | 199 | copy: |
207 | 200 | mode: 'u+rwx,go=rx' |
|
0 commit comments