Skip to content

Instantly share code, notes, and snippets.

@abdennour
Created April 26, 2019 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdennour/e0b8513031a3c15ac18bb82fea1a5917 to your computer and use it in GitHub Desktop.
Save abdennour/e0b8513031a3c15ac18bb82fea1a5917 to your computer and use it in GitHub Desktop.
playbook example
View the file *http://files.example.com/user_list.yml* from *control1*. Create a playbook in */home/ansible/exam/users.yml* that follows the instructions provided in the file.
Create the file /home/ansible/exam/users.yml containing the following:
---
- hosts: localhost
tasks:
- name: download user_list.yml
get_url:
url: http://files.example.com/user_list.yml
dest: /home/ansible/files/user_list.yml
- hosts: node1
become: yes
vars_files:
- /home/ansible/files/user_list.yml
tasks:
- name: create groups from file
group:
name: "{{ item }}"
with_items:
- "{{ user_groups }}"
- name: create users for each group in staff
user:
name: "{{ item }}"
group: staff
with_items:
- "{{ staff }}"
- name: create users for each group in students
user:
name: "{{ item }}"
group: students
with_items:
- "{{ students }}"
- name: create users for each group in faculty
user:
name: "{{ item }}"
group: faculty
with_items:
- "{{ faculty }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment