main.yml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. ---
  2. - name: Enable crb on CentOS 9
  3. shell:
  4. cmd: dnf config-manager --set-enabled crb
  5. changed_when: false
  6. when:
  7. - ansible_distribution == "CentOS"
  8. - ansible_distribution_major_version == "9"
  9. - name: Enable EPEL Repo on CentOS 7/8
  10. package:
  11. name: epel-release
  12. state: present
  13. when:
  14. - ansible_distribution == "CentOS"
  15. - ansible_distribution_major_version|int > 9
  16. - name: Check for EPEL Repo on CentOS 9
  17. shell:
  18. cmd: rpm -q epel-release
  19. changed_when: false
  20. failed_when: false
  21. register: epel_check
  22. when:
  23. - ansible_distribution == "CentOS"
  24. - ansible_distribution_major_version == "9"
  25. - name: Enable EPEL Repo on CentOS 9
  26. dnf:
  27. name:
  28. - https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/Packages/e/epel-release-9-4.el9.noarch.rpm
  29. - https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/Packages/e/epel-next-release-9-4.el9.noarch.rpm
  30. state: present
  31. disable_gpg_check: yes
  32. when:
  33. - ansible_distribution == "CentOS"
  34. - ansible_distribution_major_version == "9"
  35. - epel_check.rc|int == 1
  36. - name: Enable PowerTools on CentOS 8
  37. lineinfile:
  38. path: /etc/yum.repos.d/CentOS-{% if ansible_lsb.id == 'CentOSStream' %}Stream-{% endif %}PowerTools.repo
  39. regexp: '^enabled='
  40. line: 'enabled=1'
  41. when:
  42. - ansible_distribution == 'CentOS'
  43. - ansible_distribution_major_version == "8"
  44. - name: Check for RPMFusion rpms
  45. shell:
  46. cmd: rpm -q rpmfusion-free-release
  47. failed_when: false
  48. changed_when: false
  49. register: rpmfusion_check
  50. - name: Download RPMFusion .rpms
  51. get_url:
  52. url: "{{ item }}"
  53. dest: /home/ansible/{{ item | basename }}
  54. owner: ansible
  55. group: ansible
  56. mode: '0644'
  57. loop:
  58. - https://download1.rpmfusion.org/free/{{ 'el' if ansible_distribution == 'CentOS' else 'fedora' }}/rpmfusion-free-release-{{ ansible_distribution_major_version }}.noarch.rpm
  59. - https://download1.rpmfusion.org/nonfree/{{ 'el' if ansible_distribution == 'CentOS' else 'fedora' }}/rpmfusion-nonfree-release-{{ ansible_distribution_major_version }}.noarch.rpm
  60. loop_control:
  61. label: "{{ item | basename }}"
  62. register: rpmfusion_repos
  63. when:
  64. - ansible_distribution == 'CentOS' or ansible_distribution == 'Fedora'
  65. - ansible_distribution_major_version != "9" # no RPMFusion yet for CentOS Stream 9
  66. - rpmfusion_check.rc != "0"
  67. - name: Install RPMFusion .rpms
  68. yum:
  69. name:
  70. - /home/ansible/rpmfusion-free-release-{{ ansible_distribution_major_version }}.noarch.rpm
  71. - /home/ansible/rpmfusion-nonfree-release-{{ ansible_distribution_major_version }}.noarch.rpm
  72. disable_gpg_check: yes
  73. state: present
  74. when:
  75. - rpmfusion_repos is defined
  76. - rpmfusion_repos.changed
  77. - ansible_distribution == 'CentOS' or ansible_distribution == 'Fedora'
  78. - ansible_distribution_major_version != "9" # no RPMFusion yet for CentOS Stream 9
  79. - name: Combine Packages (RPM)
  80. set_fact:
  81. all_pkgs: "{{ all_pkgs | default([]) | union(item) }}"
  82. loop:
  83. - "{{ common_pkgs }}"
  84. - "{{ common_pkgs_rpm }}"
  85. - "{{ host_pkgs | default([]) }}"
  86. loop_control:
  87. label: "{{ all_pkgs | default([]) | length }} Packages"
  88. when:
  89. - ansible_distribution == 'CentOS' or ansible_distribution == 'Fedora'
  90. - name: Combine Packages (DEB)
  91. set_fact:
  92. all_pkgs: "{{ all_pkgs | default([]) | union(item) }}"
  93. loop:
  94. - "{{ common_pkgs }}"
  95. - "{{ common_pkgs_deb }}"
  96. - "{{ host_pkgs | default([]) }}"
  97. when:
  98. - ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
  99. - name: Install packages
  100. package:
  101. name: "{{ all_pkgs }}"
  102. state: present
  103. when:
  104. - all_pkgs is defined
  105. - name: Install ansible SSH keys
  106. authorized_key:
  107. user: ansible
  108. state: present
  109. exclusive: yes
  110. key: "{{ ssh_ansible_keys | join('\n') }}"
  111. when:
  112. - ansible_os_family != 'LibreELEC'
  113. tags: ssh
  114. - name: Install root SSH keys
  115. authorized_key:
  116. user: root
  117. state: present
  118. exclusive: yes
  119. key: "{{ ssh_root_keys | union(host_ssh_root_keys) | join('\n') }}"
  120. tags: ssh
  121. - name: Create additional users
  122. user:
  123. name: "{{ item.name }}"
  124. uid: "{{ item.uid }}"
  125. state: present
  126. shell: "{{ item.shell | default('/bin/bash') }}"
  127. create_home: "{{ item.create_home | default('yes') }}"
  128. with_items:
  129. - "{{ users }}"
  130. when:
  131. - item.name is defined
  132. - item.uid is defined
  133. - name: Add Bash aliases for root user
  134. lineinfile:
  135. dest: /root/.bashrc
  136. create: yes
  137. mode: '0644'
  138. line: "alias {{ item.alias }}='{{ item.command }}'"
  139. regexp: "^alias {{ item.alias }}="
  140. with_items:
  141. - "{{ common_bash_aliases | default('') }}"
  142. - "{{ host_bash_aliases | default('') }}"
  143. when:
  144. - (item.user is not defined or item.user == 'root')
  145. - item.alias is defined
  146. - item.command is defined
  147. - ansible_os_family != 'LibreELEC'
  148. tags: aliases
  149. - name: Add bash aliases for non-root users
  150. lineinfile:
  151. dest: /home/{{ item.user }}/.bashrc
  152. create: no
  153. mode: '0644'
  154. line: "alias {{ item.alias }}='{{ item.command }}'"
  155. regexp: "^alias {{ item.alias }}="
  156. register: create_alias
  157. failed_when:
  158. - create_alias.rc is defined
  159. - create_alias.rc != 257
  160. with_items:
  161. - "{{ common_bash_aliases | default('') }}"
  162. - "{{ host_bash_aliases | default('') }}"
  163. when:
  164. - item.user is defined
  165. - item.user != 'root'
  166. - item.alias is defined
  167. - item.command is defined
  168. - ansible_os_family != 'LibreELEC'
  169. tags: aliases