Skip to content

Instantly share code, notes, and snippets.

@mrcrilly
Forked from anonymous/main.yml (tasks)
Last active August 29, 2015 14:17
Show Gist options
  • Save mrcrilly/277beff5a3743e10dbad to your computer and use it in GitHub Desktop.
Save mrcrilly/277beff5a3743e10dbad to your computer and use it in GitHub Desktop.
---
- hosts: all
gather_facts: false
sudo: true
vars:
users:
user1:
name: Full Name
group: "group1"
user2:
name: Full Name
group: "group2"
user3:
name: Full Name
group: "group3"
tasks:
- name: Add all groups
group:
name: "{{item.value.group}}"
state: "present"
with_dict: users
- name: Add all users
user:
name: "{{ item.key }}"
group: "{{ item.value.group }}"
comment: "{{ item.value.name }}"
shell: "/bin/bash"
with_dict: users
register: addedusers
- name: Update the password if the user was created
user:
name: "{{item.name}}"
password: "superpassword!"
with_items: addedusers.results
when: item.changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment