Skip to content

Instantly share code, notes, and snippets.

@shgonzalez
Created December 12, 2020 14:22
Show Gist options
  • Save shgonzalez/0fce91939f7fd8c4d094d92b5d7e5b31 to your computer and use it in GitHub Desktop.
Save shgonzalez/0fce91939f7fd8c4d094d92b5d7e5b31 to your computer and use it in GitHub Desktop.
---
- name: Configure users with public keys
hosts: all
vars:
users:
- name: user1
pkey: 'ssh-rsa AAAAB3NzaC........pIun6iSsRkiJKLdVoUHJysl0ULUzXDIhVN5sIvdbhb0jBsL2/C/T5M58Q== rsa-key-20201104'
- name: user2
pkey: 'ssh-rsa AAAAB3NzaC........uuyHrEB4hi8sArdqCk+1l2SwfNtokg2PyQqx9aBIJUdcYhH8W6'
- name: user3
#pkey: 'ssh-rsa AAAAB3NzaC1yc2EAAR4ATEChQ== rsa-key-20201104'
pkey: 'ssh-rsa AAAAB3NzaC........RTxfJLoPFEvIvSeiw/0TTEWpiZQs4+GvT4XG299swVSAjmBUKNwyOF+w== rsa-key-20201204'
- name: sergio
pkey: 'ssh-rsa AAAAB3NzaC........0XYB7q/wFD3vXRUTPrWzBFa606B0zRYZN9nMQhfsmNKt+y6DEOnVAAt9jk/LZkw== sergio'
tasks:
- name: create users
user:
name: "{{ item.name }}"
comment: "{{ item.name }}"
expires: -1
loop: "{{ users }}"
loop_control:
label: "{{ item.name }}"
- name: Set authorized key taken from file
authorized_key:
user: "{{ item.name }}"
state: present
key: "{{ item.pkey }}"
loop: "{{ users }}"
loop_control:
label: "{{ item.name }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment