SSE-Lab/ansible/playbooks/bootstrap.yml

61 lines
1.6 KiB
YAML

- hosts: all
become: yes
#debugger: on_failed
tasks:
- name: Add the ansible group
group:
name: ansible
gid: 1100
state: present
- name: Add the ansible user as a system user
user:
name: ansible
uid: 1100
group: ansible
# Directly generate hash
# https://www.lisenet.com/2019/ansible-generate-crypted-passwords-for-the-user-module/
password: "{{ ansible_crypted_password | password_hash('sha512') }}"
shell: /bin/bash
# Uncomment to prevent password reset
update_password: on_create
system: yes
home: /srv/ansible
state: present
- name: Set ansible user as sudoer
copy:
content: "ansible ALL = (ALL) NOPASSWD:ALL"
dest: /etc/sudoers.d/ansible
owner: root
group: root
mode: 0440
- name: Init cache directory
ansible.builtin.file:
path: /var/cache/ansible
owner: ansible
group: ansible
state: directory
mode: u=rwx,g=rw,o=r
- name: Init etc directory
ansible.builtin.file:
path: /etc/ansible
owner: ansible
group: ansible
state: directory
mode: u=rwx,g=rw,o=r
# Inserts public keys of allowed externals users to log in as ansible
# e.g. fabio
- name: Create the .ssh directory
file: path=/srv/ansible/.ssh owner=ansible group=ansible mode=0700 state=directory
- name: Add the mandatory ssh keys to the ansible user
template: src=library/templates/ansible_auth_keys.j2 dest=/srv/ansible/.ssh/authorized_keys owner=ansible group=ansible mode=0600