-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
43 lines (39 loc) · 1.52 KB
/
playbook.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
# Initial server setup only perfomed once after new server is instanciated
# * creation of a (passwordless) sudo user
# * some really basic ssh hardening
- hosts: game_servers
remote_user: root # ???
become: false
gather_facts: false # No login before testing ssh access
tasks:
- name: Print hello to ssh user
debug:
msg: "Moin user {{ ansible_ssh_user }}"
# inspired by https://serverfault.com/questions/840156/create-non-root-user-and-disable-root-ssh-in-ansible
- name: Check ansible user
command: ssh -n -q -o BatchMode=yes -o ConnectTimeout=3 -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes {{ created_username }}@{{ inventory_hostname }} 'true'
delegate_to: 127.0.0.1
changed_when: false
failed_when: false
register: check_ansible_user
- name: Act on success
debug:
msg: "SSH login using {{ created_username }} user was successful"
when: check_ansible_user.rc == 0
- block:
- name: Act on failure
debug:
msg: "SSH login using {{ created_username }} failed, we need to run base setup to create the user"
- name: Create new user
include_role:
name: base
when: check_ansible_user.rc != 0
- hosts: game_servers
# remote_user: "{{ created_username }}" ToDo remove?
vars:
# after previously making sure initial setup is done, we will now use our non root user
ansible_ssh_user: "{{ created_username }}"
become: true
roles:
- role: ssh-hardening
- role: sauerbraten