main.yml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. uid: "{{ ansible_creation_uid }}"
  42. create_home: yes
  43. when:
  44. - ansible_os_family != 'LibreELEC'
  45. - name: Adding ansible as a sudoer
  46. copy:
  47. src: 10_ansible
  48. dest: /etc/sudoers.d/10_ansible
  49. owner: root
  50. group: root
  51. mode: '0640'
  52. when:
  53. - ansible_os_family != 'LibreELEC'
  54. - import_role:
  55. name: common
  56. - name: Ensure only key-based SSH logins are allowed
  57. lineinfile:
  58. path: /etc/ssh/sshd_config
  59. regexp: '^PasswordAuthentication'
  60. line: 'PasswordAuthentication no'
  61. state: present
  62. notify:
  63. - Restart sshd
  64. when:
  65. - ansible_os_family != 'LibreELEC' # / is mounted RO in LibreELEC