-
-
Save myles/2c1fb82c8764440756d910f981d9ff24 to your computer and use it in GitHub Desktop.
Using Ansible with_subelements
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
--- | |
# Create the user accounts. | |
- name: create the user accounts | |
user: | |
name: '{{ item.username }}' | |
state: present | |
shell: '{{ item.shell }}' | |
groups: sudo | |
generate_ssh_key: yes | |
with_items: | |
- '{{ users }}' | |
tags: | |
- common | |
- users | |
# Add the authorized keys to the user accounts. | |
- name: add ~/.ssh/authorized_keys file for the user accounts | |
authorized_key: | |
user: '{{ item.0.username }}' | |
key: "{{ item.1 }}" | |
with_subelements: | |
- '{{ users }}' | |
- authorized_keys | |
tags: | |
- common | |
- 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
--- | |
# Users | |
users: | |
- username: myles | |
shell: /bin/bash | |
authorized_keys: | |
- "{{ lookup('file', 'ssh_keys/myles_laptop.pub') }}" | |
- "{{ lookup('file', 'ssh_keys/myles_ipad.pub') }}" | |
- "{{ lookup('file', 'ssh_keys/myles_iphone.pub') }}" | |
- username: scott | |
shell: /bin/bash | |
authorized_keys: | |
- "{{ lookup('file', 'ssh_keys/scott_laptop.pub') }}" | |
- "{{ lookup('file', 'ssh_keys/scott_tablet.pub') }}" | |
- "{{ lookup('file', 'ssh_keys/scott_phone.pub') }}" | |
- "{{ lookup('file', 'ssh_keys/scott_server.pub') }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment