main.yml 1.8 KB

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