Last active
September 1, 2016 13:05
-
-
Save Appeltabak/7f20f9f6e4fed80202cc2dd5d0044b5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tasks/main.yml | |
- include: normal_user.yml | |
with_items: "{{ users }}" | |
loop_control: | |
loop_var: outer_users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tasks/normal_user.yml | |
- name: "create normal user {{ outer_users.name }}" | |
become: true | |
user: | |
name: "{{ outer_users.name }}" | |
createhome: "{{ outer_users.createhome | default(yes) }}" | |
shell: "{{ outer_users.shell | default('/bin/bash') }}" | |
state: present | |
register: user_created | |
ignore_errors: true | |
tags: | |
- user | |
# Using 'other_users' in subsequent tasks gives an error. See output | |
- debug: | |
msg: "Can't create user {{ other_users.name }} on this host using module 'user'. Trying it manually." | |
when: user_created|failed | |
tags: | |
- user,"{{ other_users.name }}" | |
- include: add_manual.yml | |
when: user_created|failed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ERROR! 'outer_users' is undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vars/main.yml | |
users: | |
- hodor: | |
name: test | |
createhome: yes | |
shell: /bin/bash | |
state: present |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment