fix_Ansible_user.playbook.yaml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ---
  2. - name: Ensure Ansible user has the correct keys, permissions, groups, etc.
  3. hosts: all
  4. gather_facts: true
  5. become: true
  6. tasks:
  7. - name: "Ansible_user_info"
  8. include_vars:
  9. dir: "include/Ansible_user"
  10. ignore_unknown_extensions: True
  11. extensions: [ 'userinfo.yaml', 'yaml' ]
  12. - debug:
  13. msg: "{{ username }}"
  14. - name: "Add/modify Ansible user with a specific uid, passwd hash & public key(s)"
  15. user:
  16. name: "Ansible"
  17. comment: "Ansible user"
  18. shell: /bin/bash
  19. uid: "{{ uid }}"
  20. password: "{{ shadowhash }}"
  21. password_expire_max: 0
  22. password_expire_min: 0
  23. password_lock: false
  24. update_password: always
  25. home: '/home/Ansible'
  26. state: present
  27. - name: "Append appropriate groups for Ansible, REMOVE other groups"
  28. user:
  29. name: 'Ansible'
  30. groups: "admin,sudo,wheel"
  31. ignore_errors: true
  32. append: false
  33. user: 'Ansible'
  34. state: present
  35. key: '{{ item }}'
  36. with_file:
  37. - "{{ pubkeysfile }}"
  38. - debug:
  39. msg:
  40. - " PUBKEYSFILE was read in as {{ pubkeysfile }} "