Skip to content

Instantly share code, notes, and snippets.

@myles myles/tasks.yml Secret
Created Oct 31, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.