main.yml 5.6 KB

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