Last active
June 2, 2021 13:24
-
-
Save msato0731/4fa53792082ffb5eff1a91f1abeef648 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
--- | |
- hosts: all | |
become: yes | |
vars_files: | |
- var.yaml | |
tasks: | |
- name: add a admin group | |
group: name=admin state=present | |
- name: add a new user | |
user: | |
name: "{{ item.name }}" | |
uid: "{{ item.uid}}" | |
password: "{{ item.password | password_hash('sha512') }}" | |
group: admin | |
groups: wheel | |
state: present | |
with_items: | |
- "{{ users }}" | |
- name: mkdir .ssh | |
file: | |
path: /home/{{ item.name }}/.ssh/ | |
state: directory | |
owner: "{{ item.name }}" | |
group: admin | |
mode: 0700 | |
with_items: | |
- "{{ users }}" | |
- name: add authorized_key | |
authorized_key: | |
user: "{{ item.name }}" | |
key: "{{ lookup('file', '/home/vagrant/ansible/ansible_useradd/publickey/{{ item.name }}/id_rsa.pub') }}" | |
with_items: | |
- "{{ users }}" |
This file contains hidden or 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: | |
- { name: 'hoge1', uid: '1011', password: 'password' } | |
- { name: 'hoge2', uid: '1012', password: 'password' } | |
- { name: 'hoge3', uid: '1013', password: 'password'} | |
- { name: 'hoge4', uid: '1014', password: 'password' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've added this to my playbook. It will remove users if its a revoked user and the file exists: