main.yml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ---
  2. - name: Install Python without using Ansible modules
  3. raw: >
  4. bash -c "test -e /usr/bin/python3 ||
  5. (test -e /usr/bin/yum && yum install -y python3) ||
  6. (apt install -y python3 python-apt) ||
  7. grep -i LibreELEC /etc/os-release"
  8. changed_when: false
  9. - name: Gather facts now that Python is installed
  10. setup:
  11. - name: Install sudo and lsb (RPM)
  12. package:
  13. name:
  14. - sudo
  15. - "{% if ansible_distribution_major_version != '9' %}redhat-lsb-core{% else %}python3-libselinux{% endif %}"
  16. state: present
  17. when:
  18. - ansible_distribution == 'CentOS' or ansible_distribution == 'Fedora'
  19. - name: Install sudo and lsb (DEB)
  20. package:
  21. name:
  22. - sudo
  23. - lsb-release
  24. state: present
  25. when:
  26. - ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
  27. - name: Install SELinux Python Modules (Fedora)
  28. package:
  29. name:
  30. - python3-libselinux
  31. state: present
  32. when:
  33. - ansible_distribution == 'Fedora'
  34. - name: Gather facts again now that lsb is installed
  35. setup:
  36. - name: Creating ansible user
  37. user:
  38. name: ansible
  39. state: present
  40. shell: /bin/bash
  41. create_home: yes
  42. when:
  43. - ansible_os_family != 'LibreELEC'
  44. - name: Adding ansible as a sudoer
  45. copy:
  46. src: 10_ansible
  47. dest: /etc/sudoers.d/10_ansible
  48. owner: root
  49. group: root
  50. mode: '0640'
  51. when:
  52. - ansible_os_family != 'LibreELEC'
  53. - import_role:
  54. name: common
  55. - name: Ensure only key-based SSH logins are allowed
  56. lineinfile:
  57. path: /etc/ssh/sshd_config
  58. regexp: '^PasswordAuthentication'
  59. line: 'PasswordAuthentication no'
  60. state: present
  61. notify:
  62. - Restart sshd
  63. when:
  64. - ansible_os_family != 'LibreELEC' # / is mounted RO in LibreELEC