add_linuxgroup_users-wheel.playbook.yaml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ---
  2. - name: Ensure Linux group users are configured with UIDs, passwords, groups and keys
  3. hosts: all
  4. gather_facts: true
  5. become: True
  6. tasks:
  7. - name: "userinfofile"
  8. include_vars:
  9. dir: "include/linux_group_users"
  10. ignore_unknown_extensions: True
  11. extensions: [ 'userinfo.yaml', 'yaml' ]
  12. - debug:
  13. msg: "{{ username }}"
  14. - name: "Add/modify a user with a specific uid, passwd hash & public key(s)"
  15. user:
  16. name: "{{ username }}"
  17. comment: "{{ fullname }}"
  18. shell: /bin/bash
  19. uid: "{{ uid }}"
  20. password: "{{ shadowhash }}"
  21. state: present
  22. - name: "Append the wheel group"
  23. user:
  24. name: "{{ username }}"
  25. groups: wheel
  26. append: yes
  27. - name: "Append the sudonopsswd group"
  28. user:
  29. name: "{{ username }}"
  30. groups: sudonopsswd
  31. append: yes
  32. - name: "Append/modify the *sudo* group to above user if it exists on the system"
  33. user:
  34. name: "{{ username }}"
  35. with_items:
  36. - { groups: 'sudo' }
  37. - { append: 'yes' }
  38. ignore_errors: true
  39. - name: "Append/modify the *wheel* group to above user if it exists on the system"
  40. user:
  41. name: "{{ username }}"
  42. with_items:
  43. - { groups: 'wheel' }
  44. - { append: 'yes' }
  45. ignore_errors: true
  46. - name: "Append/modify the *sudonopsswd* group to above user if it exists on the system"
  47. user:
  48. name: "{{ username }}"
  49. with_items:
  50. - { groups: 'sudonopsswd' }
  51. - { append: 'yes' }
  52. ignore_errors: false
  53. - name: "Set auth keys for user"
  54. authorized_key:
  55. user: "{{ username }}"
  56. state: present
  57. key: '{{ item }}'
  58. with_file:
  59. - "{{ pubkeysfile }}"
  60. - debug:
  61. msg:
  62. - " PUBKEYSFILE was read in as {{ pubkeysfile }} "