Guest User

Untitled

a guest
Sep 14th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. ---
  2. - hosts: all
  3. gather_facts: false
  4. vars:
  5. local_group_info:
  6.  
  7. - name : developer group
  8. which_users :
  9. - mike
  10. - george
  11. which_groups :
  12. - adm
  13. - www-data
  14. on_hosts :
  15. - test.sv1.org
  16. - punchy.sv1.org
  17.  
  18. - name: admin group
  19. which_users:
  20. - kelly
  21. which_groups:
  22. - sudo
  23. on_hosts :
  24. - test.sv1.org
  25.  
  26. tasks:
  27. - name: Add users to local groups if current host matches
  28. when: inventory_hostname in item.0.on_hosts or 'all' in item.0.on_hosts
  29. debug:
  30. msg: "user {{ item.0.which_users }} should be in group {{ item.1 }}"
  31. with_subelements:
  32. - "{{ local_group_info }}"
  33. - which_groups
  34.  
  35. PLAY [all] **************************************************************************************************************************
  36.  
  37. TASK [Add users to local groups if current host matches] ****************************************************************************
  38. ok: [test.sv1.org] => (item=[{u'which_users': [u'mike', u'george'], u'name': u'developer group', u'on_hosts': [u'test.sv1.org', u'punchy.sv1.org']}, u'adm']) => {
  39. "msg": "user [u'mike', u'george'] should be in group adm"
  40. }
  41. ok: [test.sv1.org] => (item=[{u'which_users': [u'mike', u'george'], u'name': u'developer group', u'on_hosts': [u'test.sv1.org', u'punchy.sv1.org']}, u'www-data']) => {
  42. "msg": "user [u'mike', u'george'] should be in group www-data"
  43. }
  44. ok: [test.sv1.org] => (item=[{u'which_users': [u'kelly'], u'name': u'admin group', u'on_hosts': [u'test.sv1.org']}, u'sudo']) => {
  45. "msg": "user [u'kelly'] should be in group sudo"
  46. }
  47.  
  48. PLAY RECAP **************************************************************************************************************************
  49. test.sv1.org : ok=1 changed=0 unreachable=0 failed=0
Add Comment
Please, Sign In to add comment