theshire/.archive/ansible/main/playbooks/cluster-add-user.yaml

44 lines
1.3 KiB
YAML

---
- name: Add user 'jahanson' and add to sudo group
hosts: all
become: true
tasks:
- name: Create user 'jahanson'
ansible.builtin.user:
name: jahanson
state: present
- name: Add user 'jahanson' to sudo group
when: ansible_user == 'root'
ansible.builtin.user:
name: jahanson
groups: sudo
append: true
- name: User Configuration | SSH keys
ansible.posix.authorized_key:
user: "jahanson"
key: "https://github.com/jahanson.keys"
- name: User Configuration | Silence login
ansible.builtin.file:
dest: "{{ '/home/' + ansible_user if ansible_user != 'root' else '/root' }}/.hushlogin"
state: touch
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0644"
modification_time: preserve
access_time: preserve
- name: Copy .vimrc file
ansible.builtin.copy:
src: "files/.vimrc"
dest: "/home/jahanson/.vimrc"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0644"
- name: User Configuration | Add user to sudoers
ansible.builtin.copy:
content: "jahanson ALL=(ALL:ALL) NOPASSWD:ALL"
dest: "/etc/sudoers.d/jahanson"
owner: root
group: root
mode: "0440"