main.yml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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: Download RPMFusion .rpms
  47. get_url:
  48. url: "{{ item }}"
  49. dest: /home/ansible/{{ item | basename }}
  50. owner: ansible
  51. group: ansible
  52. mode: '0644'
  53. loop:
  54. - https://download1.rpmfusion.org/free/{{ 'el' if ansible_distribution == 'CentOS' else 'fedora' }}/rpmfusion-free-release-{{ ansible_distribution_major_version }}.noarch.rpm
  55. - https://download1.rpmfusion.org/nonfree/{{ 'el' if ansible_distribution == 'CentOS' else 'fedora' }}/rpmfusion-nonfree-release-{{ ansible_distribution_major_version }}.noarch.rpm
  56. loop_control:
  57. label: "{{ item | basename }}"
  58. register: rpmfusion_repos
  59. when:
  60. - ansible_distribution == 'CentOS' or ansible_distribution == 'Fedora'
  61. - ansible_distribution_major_version != "9" # no RPMFusion yet for CentOS Stream 9
  62. - '"rpmfusion" not in ansible_facts.packages|list'
  63. - name: Install RPMFusion .rpms
  64. yum:
  65. name:
  66. - /home/ansible/rpmfusion-free-release-{{ ansible_distribution_major_version }}.noarch.rpm
  67. - /home/ansible/rpmfusion-nonfree-release-{{ ansible_distribution_major_version }}.noarch.rpm
  68. disable_gpg_check: yes
  69. state: present
  70. when:
  71. - rpmfusion_repos is defined
  72. - rpmfusion_repos.changed
  73. - ansible_distribution == 'CentOS' or ansible_distribution == 'Fedora'
  74. - ansible_distribution_major_version != "9" # no RPMFusion yet for CentOS Stream 9
  75. - name: Combine Packages (RPM)
  76. set_fact:
  77. all_pkgs: "{{ all_pkgs | default([]) | union(item) }}"
  78. loop:
  79. - "{{ common_pkgs }}"
  80. - "{{ common_pkgs_rpm }}"
  81. - "{{ host_pkgs | default([]) }}"
  82. loop_control:
  83. label: "{{ all_pkgs | default([]) | length }} Packages"
  84. when:
  85. - ansible_distribution == 'CentOS' or ansible_distribution == 'Fedora'
  86. - name: Combine Packages (DEB)
  87. set_fact:
  88. all_pkgs: "{{ all_pkgs | default([]) | union(item) }}"
  89. loop:
  90. - "{{ common_pkgs }}"
  91. - "{{ common_pkgs_deb }}"
  92. - "{{ host_pkgs | default([]) }}"
  93. when:
  94. - ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
  95. - name: Install packages
  96. package:
  97. name: "{{ all_pkgs }}"
  98. state: present
  99. when:
  100. - all_pkgs is defined
  101. - name: Install ansible SSH keys
  102. authorized_key:
  103. user: ansible
  104. state: present
  105. exclusive: yes
  106. key: "{{ ssh_ansible_keys | join('\n') }}"
  107. when:
  108. - ansible_os_family != 'LibreELEC'
  109. tags: ssh
  110. - name: Install root SSH keys
  111. authorized_key:
  112. user: root
  113. state: present
  114. exclusive: yes
  115. key: "{{ ssh_root_keys | union(host_ssh_root_keys) | join('\n') }}"
  116. tags: ssh
  117. - name: Install pi SSH keys
  118. authorized_key:
  119. user: pi
  120. state: present
  121. exclusive: yes
  122. key: "{{ ssh_root_keys | join('\n') }}"
  123. when:
  124. - '"libreelec" in group_names'
  125. tags: ssh
  126. - name: Add Bash aliases for root user
  127. lineinfile:
  128. dest: /root/.bashrc
  129. create: yes
  130. mode: '0644'
  131. line: "alias {{ item.alias }}='{{ item.command }}'"
  132. regexp: "^alias {{ item.alias }}="
  133. with_items:
  134. - "{{ common_bash_aliases | default('') }}"
  135. - "{{ host_bash_aliases | default('') }}"
  136. when:
  137. - (item.user is not defined or item.user == 'root')
  138. - item.alias is defined
  139. - item.command is defined
  140. - ansible_os_family != 'LibreELEC'
  141. tags: aliases
  142. - name: Add bash aliases for non-root users
  143. lineinfile:
  144. dest: /home/{{ item.user }}/.bashrc
  145. create: no
  146. mode: '0644'
  147. line: "alias {{ item.alias }}='{{ item.command }}'"
  148. regexp: "^alias {{ item.alias }}="
  149. register: create_alias
  150. failed_when:
  151. - create_alias.rc is defined
  152. - create_alias.rc != 257
  153. with_items:
  154. - "{{ common_bash_aliases | default('') }}"
  155. - "{{ host_bash_aliases | default('') }}"
  156. when:
  157. - item.user is defined
  158. - item.user != 'root'
  159. - item.alias is defined
  160. - item.command is defined
  161. - ansible_os_family != 'LibreELEC'
  162. tags: aliases