Advertisement
CaseyRichins

Multi-user manage Ansible

Jun 7th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. roles/common/tasks/users.yml
  2. ---
  3. - name: Import User Variables
  4.   include_vars: 'defaults/{{ item.access }}.yml'
  5.   with_flattened:
  6.     - { access: sysop, exec: '{{ sysop_access | default(false) }}' }
  7.     - { access: admin, exec: '{{ admin_access | default(false) }}' }
  8.     - { access: l3, exec: '{{ l3_access | default(false) }}' }
  9.     - { access: l2, exec: '{{ l2_access | default(false) }}'  }
  10.     - { access: l1, exec: '{{ l1_access | default(false) }}'  }
  11.     - { access: terminated, exec: '{{ terminated | default(true) }}' }
  12.   when: item.access is defined and item.exec is defined and item.exec != false
  13.   register: accounts
  14.  
  15. - name: Manage user accounts
  16.   user:
  17.     name: '{{ item.name }}'
  18.     uid: '{{ item.uid | default(omit) }}'
  19.     group: '{{ item.group | default(item.name) }}'
  20.     state: '{{ item.state | default("present") }}'
  21.     comment: '{{ item.comment | default(omit) }}'
  22.     system: '{{ item.system | default(omit) }}'
  23.     shell: '{{ item.shell | default(default_shell) }}'
  24.     home: '{{ item.home | default(omit) }}'
  25.     createhome: '{{ item.createhome | default(omit) }}'
  26.     expires: '{{ item.expires | default(omit) }}'
  27.     remove: '{{ item.remove_home | default(omit) }}'
  28.     update_password: '{{ item.update_password | default("on_create") }}'
  29.     password: '{{ item.password| default("*") }}'
  30.   with_items:
  31.       #    - "{{ users }}"
  32.       - " {{ accounts }}"
  33.       #    - users_all
  34.   when: ((item.name is defined and item.name and item.name != 'root') and
  35.         (item.state is undefined or (item.state is defined and item.state)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement