-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.yml
More file actions
55 lines (47 loc) · 1.58 KB
/
Copy pathbootstrap.yml
File metadata and controls
55 lines (47 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
- name: Bootstrap debian minimal for ansible usage.
hosts: all
remote_user: root
pre_tasks:
- name: Pre-Tasks | Update apt package cache.
ansible.builtin.apt:
update_cache: true
changed_when: false
- name: Pre-Tasks | Install sudo apt package.
ansible.builtin.apt:
name: sudo
state: present
tasks:
- name: Create the ansible user group.
ansible.builtin.group:
name: "{{ ansible_system_user }}"
state: present
- name: Create the ansible user.
ansible.builtin.user:
name: "{{ ansible_system_user }}"
group: "{{ ansible_system_user }}"
shell: /bin/bash
create_home: true
state: present
- name: Enable passwordless sudo for the ansible user.
ansible.builtin.copy:
dest: "/etc/sudoers.d/{{ ansible_system_user }}"
content: "{{ ansible_system_user }} ALL=(ALL) NOPASSWD:ALL\n"
owner: root
group: root
mode: "0440"
validate: "visudo -cf %s"
- name: Copy public ssh key for the ansible user.
ansible.posix.authorized_key:
user: "{{ ansible_system_user }}"
key: "{{ ansible_pubkey }}"
state: present
- name: Verify ansible user can access host via SSH.
hosts: all
remote_user: "{{ ansible_system_user }}"
become: true
tasks:
- name: Confirm we are not logged in as root.
ansible.builtin.assert:
that: ansible_user != 'root'
fail_msg: "Still running as root - bootstrap failed."
success_msg: "Running as {{ ansible_user }} with sudo. Bootstrap succeeded."