-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.yml
110 lines (93 loc) · 2.93 KB
/
setup.yml
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
- name: Install Docker, Docker Compose and create a new user
hosts: remote_servers
become: true
vars:
docker_gpg_key_url: "https://download.docker.com/linux/ubuntu/gpg"
docker_repo: "deb https://download.docker.com/linux/ubuntu focal stable"
pub_key: "{{ lookup('file', pub_key_file) }}"
tasks:
- name: Validate not empty pub_key variable
assert:
that:
- pub_key != ""
fail_msg: "pub_key not found"
success_msg: "pub_key is found"
- name: Install required system packages
ansible.builtin.apt:
update_cache: true
upgrade: dist
cache_valid_time: 3600
- name: Install apt-transport-https, ca-certificates, curl and software-properties-common
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
state: latest
update_cache: true
- name: Add Docker GPG apt Key
ansible.builtin.apt_key:
url: "{{ docker_gpg_key_url }}"
state: present
- name: Add Docker Repository
ansible.builtin.apt_repository:
repo: "{{ docker_repo }}"
state: present
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
- name: Install Docker CE
ansible.builtin.apt:
name: docker-ce
state: latest
- name: Install Docker Compose Plugin
ansible.builtin.apt:
name: docker-compose-plugin
state: latest
- name: Enable and start Docker services
ansible.builtin.systemd:
name: docker
enabled: true
state: started
- name: Ensure group '{{ new_user }}' exists
ansible.builtin.group:
name: "{{ new_user }}"
state: present
- name: Ensure group 'sudo' exists
ansible.builtin.group:
name: sudo
state: present
- name: Ensure group 'docker' exists
ansible.builtin.group:
name: docker
state: present
- name: Ensure user '{{ new_user }}' exists
ansible.builtin.user:
name: "{{ new_user }}"
password: "{{ 'password' | password_hash('sha512') }}"
groups: [ "{{ new_user }}", sudo, docker ]
state: present
createhome: yes
system: yes
shell: /bin/bash
- name: Ensure '{{ new_user }}' has .ssh directory
ansible.builtin.file:
path: /home/{{ new_user }}/.ssh
state: directory
owner: "{{ new_user }}"
group: "{{ new_user }}"
mode: '0700'
- name: Ensure '{{ new_user }}' has .ssh/authorized_keys file
ansible.builtin.file:
path: /home/{{ new_user }}/.ssh/authorized_keys
state: touch
owner: "{{ new_user }}"
group: "{{ new_user }}"
mode: '0600'
- name: Add public SSH key to authorized_keys
authorized_key:
user: "{{ new_user }}"
state: present
key: "{{ pub_key }}"