-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.yml
74 lines (71 loc) · 1.98 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
---
- name: Workstation set-up
hosts: workstation
become: true
become_user: root
tasks:
- name: Adding Student user
ansible.builtin.user:
name: student
password: $5$FZdHme.GElC8xy/T$45vf455zBbUvXWlhrEAkZEQjabCyqgPpw.JDPb1Xzu9
comment: Ansible managed user
shell: /bin/bash
generate_ssh_key: yes
ssh_key_bits: 2048
ssh_key_file: /home/student/.ssh/id_rsa
groups: wheel
append: yes
- name: Adding hosts to /etc/hosts
blockinfile:
path: /etc/hosts
block: |
192.168.33.51 server1
192.168.33.52 server2
192.168.33.53 server3
- name: Adding hosts to /etc/hosts
blockinfile:
path: /home/student/.ssh/config
create: true
mode: '0600'
owner: student
group: student
block: |
Host s1
Hostname server1
User ansible
IdentityFile ~/.ssh/id_rsa
Host s2
Hostname server2
User ansible
IdentityFile ~/.ssh/id_rsa
Host s3
Hostname server3
User ansible
IdentityFile ~/.ssh/id_rsa
- name: Lab set-up
hosts: servers
become: true
become_user: root
tasks:
- name: Creating ansible user
ansible.builtin.user:
name: ansible
password: $5$EnJDhFKAB5AWftJE$q0/jnnpbfKejIp59RZjb0SYtWSB6Lr4v.UxDhpi04g2
comment: Ansible managed user
shell: /bin/bash
groups: wheel
append: yes
- name: Create .ssh directory if it does not exist
ansible.builtin.file:
path: /home/ansible/.ssh
state: directory
owner: ansible
group: ansible
mode: '0700'
- name: Copying student SSH key to ansible users on servers
ansible.builtin.copy:
src: /home/student/.ssh/id_rsa.pub
dest: /home/ansible/.ssh/authorized_keys
owner: ansible
group: ansible
mode: '0600'