|
| 1 | +--- |
| 2 | +# Common things for all cloud images |
| 3 | +- name: Packages | Add EPEL repository for EL9 |
| 4 | + when: |
| 5 | + - ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux' |
| 6 | + - ansible_distribution_major_version == '9' |
| 7 | + yum: |
| 8 | + name: epel-release |
| 9 | + state: installed |
| 10 | + |
| 11 | +- name: Packages | Install OS tools for EL9 |
| 12 | + when: |
| 13 | + - (ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux') and ansible_distribution_major_version == '9' |
| 14 | + yum: |
| 15 | + name: |
| 16 | + - screen |
| 17 | + - yum-utils |
| 18 | + - cloud-init |
| 19 | + - firewalld |
| 20 | + - python3-libselinux |
| 21 | + - python3-firewall |
| 22 | + |
| 23 | +- name: Firewalld | Start EL9 |
| 24 | + when: |
| 25 | + - ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux' |
| 26 | + - ansible_distribution_major_version == '9' |
| 27 | + - ansible_os_family == 'RedHat' |
| 28 | + service: |
| 29 | + name: firewalld |
| 30 | + state: started |
| 31 | + enabled: yes |
| 32 | + |
| 33 | +- name: Add firewalld rule | EL9 |
| 34 | + when: |
| 35 | + - ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux' |
| 36 | + - ansible_distribution_major_version == '9' |
| 37 | + firewalld: port={{ item }} permanent=true state=enabled immediate=yes |
| 38 | + with_items: |
| 39 | + - 80/tcp |
| 40 | + - 443/tcp |
| 41 | + |
| 42 | +- name: cleanup cache | Cleanup cache |
| 43 | + file: path={{ item }} state=absent |
| 44 | + with_items: |
| 45 | + - /var/lib/cloud/sem |
| 46 | + - /var/lib/cloud/data |
| 47 | + - /var/lib/cloud/instance |
| 48 | + - /var/lib/cloud/instances |
| 49 | + - /var/log/cloud-init.log |
| 50 | + - /var/log/cloud-init-output.log |
| 51 | + |
| 52 | +- name: create dir | Create getty@.service.d directory |
| 53 | + file: |
| 54 | + path: /etc/systemd/system/getty@.service.d |
| 55 | + state: directory |
| 56 | + |
| 57 | +- name: cloud-init | Disable console cleanup |
| 58 | + copy: |
| 59 | + content: | |
| 60 | + [Service] |
| 61 | + TTYVTDisallocate=no |
| 62 | + dest: /etc/systemd/system/getty@.service.d/nodisallocate.conf |
| 63 | + mode: 0644 |
| 64 | + |
| 65 | +- name: root password | Set root password |
| 66 | + when: ansible_virtualization_type == "virtualbox" |
| 67 | + user: |
| 68 | + name: root |
| 69 | + password: "$6$J7pGg2a7vuRTbTV5$vORqkiAKdkyomU3iYwr/SPn.yLIkGsl5ludEx5DUvGVASSTquTjOldHt/nUWrFRnJeZyzt6CIOjAcugbcfGtN1" |
| 70 | + |
| 71 | +- name: root password | Set root password |
| 72 | + when: ansible_virtualization_type == "virtualbox" |
| 73 | + command: chage -d 0 root |
| 74 | + changed_when: False |
| 75 | + |
| 76 | +- name: root password | Disable root password |
| 77 | + when: ansible_virtualization_type != "virtualbox" |
| 78 | + command: passwd --delete root |
| 79 | + changed_when: False |
| 80 | + |
| 81 | +- name: root password | Disable root password |
| 82 | + when: ansible_virtualization_type != "virtualbox" |
| 83 | + command: passwd --lock root |
| 84 | + changed_when: False |
| 85 | + |
| 86 | +- name: chronyd | Fix start-up sequence |
| 87 | + replace: |
| 88 | + dest: /usr/lib/systemd/system/chronyd.service |
| 89 | + regexp: "After=" |
| 90 | + replace: 'Before=cloud-config.target\nAfter=network-online.target ' |
| 91 | + |
| 92 | +- name: disable root user | Disable root user |
| 93 | + copy: |
| 94 | + content: | |
| 95 | + no_ssh_fingerprints: true |
| 96 | + disable_root: true |
| 97 | + dest: /etc/cloud/cloud.cfg.d/00_disable-root.cfg |
| 98 | + mode: 0644 |
| 99 | + |
| 100 | +- name: add user | Add admin user |
| 101 | + when: create_admin == "true" |
| 102 | + user: |
| 103 | + name: admin |
| 104 | + comment: Cloud User |
| 105 | + groups: wheel,adm,systemd-journal |
| 106 | + shell: /bin/bash |
| 107 | + |
| 108 | +- name: add user | Add sudo for admin user |
| 109 | + when: create_admin == "true" |
| 110 | + copy: |
| 111 | + content: | |
| 112 | + admin ALL=(ALL) NOPASSWD: ALL |
| 113 | + dest: /etc/sudoers.d/90-admin-user |
| 114 | + mode: 0440 |
| 115 | + |
| 116 | +- name: change cloud user for OVF EL9 | Change cloud user |
| 117 | + when: |
| 118 | + - create_admin == "true" |
| 119 | + - ansible_virtualization_type == "virtualbox" |
| 120 | + - ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux' |
| 121 | + - ansible_distribution_major_version == '9' |
| 122 | + replace: |
| 123 | + dest: /etc/cloud/cloud.cfg |
| 124 | + regexp: "name: cloud-user" |
| 125 | + replace: "name: admin" |
| 126 | + |
| 127 | +- name: change cloud user for AMI EL9 | Change cloud user |
| 128 | + when: |
| 129 | + - create_admin == "true" |
| 130 | + - ansible_virtualization_type != "virtualbox" |
| 131 | + - ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux' |
| 132 | + - ansible_distribution_major_version == '9' |
| 133 | + replace: |
| 134 | + dest: /etc/cloud/cloud.cfg.d/00_ol-default-user.cfg |
| 135 | + regexp: "name: ec2-user" |
| 136 | + replace: "name: admin" |
| 137 | + |
| 138 | +- name: cloud-init configuration | stat /etc/waagent.conf |
| 139 | + stat: path=/etc/waagent.conf |
| 140 | + register: waagent_conf |
| 141 | + |
| 142 | +- name: cloud-init configuration | Enable cloud-init for Azure |
| 143 | + when: waagent_conf.stat.exists |
| 144 | + replace: |
| 145 | + dest: /etc/waagent.conf |
| 146 | + regexp: "Provisioning.UseCloudInit=n" |
| 147 | + replace: "Provisioning.UseCloudInit=y" |
| 148 | + |
| 149 | +- name: Azure tweaks |
| 150 | + when: waagent_conf.stat.exists |
| 151 | + replace: |
| 152 | + dest: /usr/lib/python2.7/site-packages/azurelinuxagent/pa/deprovision/default.py |
| 153 | + regexp: "warnings, actions, deluser=deluser" |
| 154 | + replace: "warnings, actions, include_once=False, deluser=deluser" |
| 155 | + |
| 156 | +- name: PMM URL file | Add script which show PMM URL |
| 157 | + copy: |
| 158 | + src: show-url |
| 159 | + dest: /opt/show-url |
| 160 | + mode: 0755 |
| 161 | + |
| 162 | +- name: PMM URL Service | Add Service for script which show PMM URL |
| 163 | + copy: |
| 164 | + src: banner.service |
| 165 | + dest: /etc/systemd/system/banner.service |
| 166 | + mode: 0755 |
| 167 | + |
| 168 | +- name: Enable PMM URL Service | Enable PMM URL Service |
| 169 | + systemd: |
| 170 | + name: banner |
| 171 | + state: started |
| 172 | + enabled: yes |
| 173 | + |
| 174 | +- name: PMM IP in Log | Add PMM IP in Log file |
| 175 | + lineinfile: |
| 176 | + line: 'IP: \4' |
| 177 | + path: /etc/issue |
| 178 | + create: yes |
| 179 | + |
| 180 | +- import_tasks: security.yml |
| 181 | +- import_tasks: ovf.yml |
| 182 | +- import_tasks: ami.yml |
0 commit comments