-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnfs.yml
107 lines (86 loc) · 2.92 KB
/
nfs.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
---
- hosts: nfs_server
remote_user: root
tasks:
# set up NFS
- name: Ensure NFS utilities are installed.
apt:
pkg:
- nfs-common
- nfs-kernel-server
state: present
update_cache: yes
- name: Create mountable dir
file: path=/share state=directory mode=777 owner=root group=root
- name: make sure the mount drive has a filesystem
filesystem: fstype=ext4 dev=/dev/sdb1
- name: set mountpoints
mount: path=/share src=/dev/sdb1 fstype=ext4 opts=rw,sync state=mounted
- name: Create nfs4 mountable dir
file: path=/srv/nfs4/umshared state=directory mode=777 owner=root group=root
- name: set mount to nfs4
mount: path=/srv/nfs4/umshared src=/share opts=bind state=mounted fstype=ext4
- name: copy /etc/exports
template: src=exports.j2 dest=/etc/exports owner=root group=root
- name: restart nfs server
service: name=nfs-kernel-server state=restarted
- name: open firewall port for nfs
shell: ufw allow from 192.168.3.0/24 to any port nfs
args:
executable: /bin/bash
# create an admin user
- name: create hashed password
command: openssl passwd -1 {{ admin_password }}
register: result
- set_fact:
hashed_password: "{{ result.stdout }}"
- name: create new user
user:
name: "{{ admin_username }}"
password: "{{ hashed_password }}"
groups: sudo,netdev
shell: /bin/bash
- name: create ssh key directory
file:
path: ssh_keys
state: directory
delegate_to: 127.0.0.1
become: no
- stat:
path: ssh_keys/id_rsa_{{ admin_username }}.pub
register: status
delegate_to: 127.0.0.1
become: no
- name: create ssh key for "{{ admin_username }}"
openssh_keypair:
path: "ssh_keys/id_rsa_{{ admin_username }}"
type: rsa
size: 2048
state: present
force: no
delegate_to: 127.0.0.1
become: no
- name: copy ssh key to remote host
copy:
src: ssh_keys/id_rsa_{{ admin_username }}.pub
dest: /home/{{ admin_username }}/.ssh/
- name: add ssh key to remote account
authorized_key:
user: "{{ admin_username }}"
key: "{{ lookup('file', 'ssh_keys/id_rsa_{{ admin_username }}.pub') }}"
# remove root access now we have an admin user
- name: Disallow password authentication
lineinfile: dest=/etc/ssh/sshd_config
regexp="^PasswordAuthentication"
line="PasswordAuthentication no"
state=present
notify: Restart ssh
- name: Disallow root SSH access
lineinfile: dest=/etc/ssh/sshd_config
regexp="^PermitRootLogin"
line="PermitRootLogin no"
state=present
notify: Restart ssh
handlers:
- name: Restart ssh
service: name=ssh state=restarted