main.yml 3.41 KB
Newer Older
Lars Beckers's avatar
Lars Beckers committed
1
2
3
4
---
# file: roles/nfs-server/tasks/main.yml

- name: ensure nfs server utils are installed
Robin Sonnabend's avatar
Robin Sonnabend committed
5
6
7
8
9
10
11
12
  apt:
    name:
      - nfs-common
      - nfs-kernel-server
      - msktutil
      - librpcsecgss3
      - libgssrpc4
    state: present
Lars Beckers's avatar
Lars Beckers committed
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
  tags:
    - nfs-server
    - packages

- name: ensure default umask and other user related stuff
  copy: src=login.defs dest=/etc/login.defs owner=root group=root mode=0644
  tags:
    - nfs-server
    - umask
    - config

- name: ensure exports configuration is in place
  template: src=exports.j2 dest=/etc/exports owner=root group=root mode=0644
  notify:
    - restart nfs-server
  tags:
    - nfs-server
    - config

- name: ensure nfs-common is configured
  copy: src=nfs-common dest=/etc/default/nfs-common owner=root group=root mode=0644
  notify:
    - restart nfs-server
  tags:
    - nfs-server
    - config

- name: ensure nfs-kernel-server is configured
  copy: src=nfs-kernel-server dest=/etc/default/nfs-kernel-server owner=root group=root mode=0644
  notify:
    - restart nfs-server
  tags:
    - nfs-server
    - config

- name: ensure nfs-server is enabled and running
49
  service: name=nfs-server state=started enabled=yes
Lars Beckers's avatar
Lars Beckers committed
50
51
52
53
54
  tags:
    - nfs-server
    - service

- name: ensure that there is a keytab available
Hinrikus Wolf's avatar
Hinrikus Wolf committed
55
  file: path=/etc/krb5.keytab state=file
Lars Beckers's avatar
Lars Beckers committed
56
57
58
  tags:
    - nfs-server
    - service-principal
59
  when: nfs_krb is defined
Lars Beckers's avatar
Lars Beckers committed
60
61

- name: check that we have a valid service principal
Hinrikus Wolf's avatar
Hinrikus Wolf committed
62
  shell: klist -k /etc/krb5.keytab | grep "nfs/{{ ansible_fqdn }}"
Lars Beckers's avatar
Lars Beckers committed
63
64
65
66
67
  register: principal
  failed_when: False
  tags:
    - nfs-server
    - service-principal
68
  when: nfs_krb is defined
Lars Beckers's avatar
Lars Beckers committed
69
70
71

- block:
    - name: create service principal
Hinrikus Wolf's avatar
Hinrikus Wolf committed
72
      command: samba-tool spn add "nfs/{{ ansible_fqdn }}" "{{ ansible_hostname | upper }}$"
Hinrikus Wolf's avatar
Hinrikus Wolf committed
73
      delegate_to: "{{ hostvars[groups['ad-server'][0]]['ansible_host'] }}"
Lars Beckers's avatar
Lars Beckers committed
74
75
76
77
78
      tags:
        - nfs-server
        - service-principal

    - name: export keytab
Hinrikus Wolf's avatar
Hinrikus Wolf committed
79
80
      command: samba-tool domain exportkeytab "/root/{{ ansible_fqdn }}.keytab" --principal "nfs/{{ ansible_fqdn }}"
      args:
Lars Beckers's avatar
Lars Beckers committed
81
        creates: "/root/{{ ansible_fqdn }}.keytab"
Hinrikus Wolf's avatar
Hinrikus Wolf committed
82
      delegate_to: "{{ hostvars[groups['ad-server'][0]]['ansible_host'] }}"
Lars Beckers's avatar
Lars Beckers committed
83
84
85
86
87
88
89
      tags:
        - nfs-server
        - service-principal

    - name: copy keytab
      synchronize:
        src: "/root/{{ ansible_fqdn }}.keytab"
Hinrikus Wolf's avatar
Hinrikus Wolf committed
90
91
        dest: "/root/{{ ansible_fqdn }}.keytab"
      delegate_to: "{{ hostvars[groups['ad-server'][0]]['ansible_host'] }}"
Lars Beckers's avatar
Lars Beckers committed
92
93
94
95
96
      tags:
        - nfs-server
        - service-principal

    - name: ensure pexpect is installed
97
      apt: name=python-pexpect state=present
Lars Beckers's avatar
Lars Beckers committed
98
99
100
101
102
      tags:
        - nfs-server
        - service-principal

    - name: merge keytabs
Hinrikus Wolf's avatar
Hinrikus Wolf committed
103
104
105
106
107
108
109
110
      expect:
        command: ktutil
        responses:
          ktutil(.*):
            - rkt /etc/krb5.keytab
            - "rkt /root/{{ ansible_fqdn }}.keytab"
            - wkt /etc/krb5.keytab
            - exit
Lars Beckers's avatar
Lars Beckers committed
111
112
113
114
115
116
117
118
      notify:
        - restart nfs-server
      tags:
        - nfs-server
        - service-principal

    - name: remove keytab at kdc
      file: path="/root/{{ ansible_fqdn }}.keytab" state=absent
Hinrikus Wolf's avatar
Hinrikus Wolf committed
119
      delegate_to: "{{ hostvars[groups['ad-server'][0]]['ansible_host'] }}"
Lars Beckers's avatar
Lars Beckers committed
120
121
122
123
124
125
126
127
128
129
      tags:
        - nfs-server
        - service-principal

    - name: remove keytab at host
      file: path="/root/{{ ansible_fqdn }}.keytab" state=absent
      tags:
        - nfs-server
        - service-principal
  when: principal.rc == 1
130
  when: nfs_krb is defined
Lars Beckers's avatar
Lars Beckers committed
131
132

- meta: flush_handlers