-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-ansible.yml
67 lines (66 loc) · 1.9 KB
/
setup-ansible.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
#################################################
# DO Community Playbooks: Initial Server Setup
#################################################
---
- hosts: all
become: true
vars:
- create_user: devops
- userpass: newpassword
tasks:
- name: Update and upgrade apt packages
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 86400
# - name: Remove apt lock file
# file:
# state: absent
# path: "/var/lib/dpkg/lock"
# - name: Remove apt lock file2
# file:
# state: absent
# path: "/var/lib/dpkg/lock-frontend"
# - name: Update APT Cache
# apt:
# update_cache: yes
# force_apt_get: yes
# - name: Upgrade all packages to the latest version
# apt:
# name: "*"
# state: latest
# force_apt_get: yes
# Sudo Group Setup
- name: Make sure we have a 'wheel' group
group:
name: wheel
state: present
- name: Allow 'wheel' group to have passwordless sudo
lineinfile:
path: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD: ALL'
validate: '/usr/sbin/visudo -cf %s'
# User + Key Setup
- name: Create a new regular user with sudo privileges
user:
name: "{{ create_user }}"
state: present
groups: wheel
append: true
create_home: true
password: "{{ userpass | password_hash('sha512') }}"
update_password: on_create
shell: /bin/bash
- name: Set authorized key for remote user
authorized_key:
user: "{{ create_user }}"
state: present
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
- name: Disable password authentication for root
lineinfile:
path: /etc/ssh/sshd_config
state: present
regexp: '^#?PermitRootLogin'
line: 'PermitRootLogin prohibit-password'