Skip to content

Instantly share code, notes, and snippets.

@myles

myles/tasks.yml Secret

Created October 31, 2018 13:07
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 myles/2c1fb82c8764440756d910f981d9ff24 to your computer and use it in GitHub Desktop.
Save myles/2c1fb82c8764440756d910f981d9ff24 to your computer and use it in GitHub Desktop.
Using Ansible with_subelements
---
# 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
---
# 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