Skip to content

Instantly share code, notes, and snippets.

@disklosr
Created August 1, 2020 12:41
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 disklosr/1e6fe240a9a40766075e815d93a474f3 to your computer and use it in GitHub Desktop.
Save disklosr/1e6fe240a9a40766075e815d93a474f3 to your computer and use it in GitHub Desktop.
---
- hosts: "{{target}}"
become: yes
gather_facts: no
connection: ssh
vars:
- username: "{{admin_username}}"
- ansible_port: 22
- random_salt: "{{ lookup('password', '/dev/null length=8 chars=ascii_letters')}}"
tasks:
- name: Make sure we have a 'wheel' group
group:
name: wheel
state: present
- name: Wheel group users can sudo
copy:
content: '%wheel ALL=(ALL:ALL) ALL'
dest: /etc/sudoers.d/wheel
mode: 0440
- name: Create main admin user
user:
name: "{{admin_username}}"
password: "{{ ansible_become_pass | password_hash('sha512', random_salt) }}"
update_password: on_create
groups: wheel
shell: /bin/bash
- name: Setup authorized keys for user admin user
authorized_key:
user: "{{ admin_username }}"
key: '{{ item }}'
with_items: "{{ authorized_keys }}"
- name: Generate ssh key pair
openssh_keypair:
path: "/home/{{admin_username}}/.ssh/id_rsa"
owner: "{{admin_username}}"
force: no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment