summaryrefslogtreecommitdiffstats
path: root/roles/common/tasks/ipsec.yml
blob: 51d717f2c3bc1e195bc9a7957c8f274682e0632b (plain)
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
- name: Install strongSwan
  apt: pkg=strongswan-ikev2

- name: Generate a private key and a X.509 certificate for IPSec
  command: genkeypair.sh x509
                         --pubkey=/etc/ipsec.d/certs/{{ inventory_hostname }}.pem
                         --privkey=/etc/ipsec.d/private/{{ inventory_hostname }}.key
                         --dns={{ inventory_hostname }}
                         -t ecdsa -b secp521r1 -h sha512
  register: r1
  changed_when: r1.rc == 0
  failed_when: r1.rc > 1
  notify:
    - Restart IPSec

- name: Fetch the public part of IPSec's host key
  sudo: False
  # Ensure we don't fetch private data
  fetch: src=/etc/ipsec.d/certs/{{ inventory_hostname }}.pem
         dest=certs/ipsec/
         fail_on_missing=yes
         flat=yes

# Don't copy our pubkey due to a possible race condition.  Only the
# remote machine has authority regarding its key.
- name: Copy IPSec host pubkeys (except ours)
  copy: src=certs/ipsec/{{ item }}.pem
        dest=/etc/ipsec.d/certs/{{ item }}.pem
        owner=root group=root
        mode=0644
  with_items: groups.all | difference([inventory_hostname])
  register: r2
  notify:
    - Restart IPSec

- name: Configure IPSec's secrets
  template: src=etc/ipsec.secrets.j2
            dest=/etc/ipsec.secrets
            owner=root group=root
            mode=0600
  register: r3
  notify:
    - Restart IPSec

- name: Configure IPSec
  template: src=etc/ipsec.conf.j2
            dest=/etc/ipsec.conf
            owner=root group=root
            mode=0644
  register: r4
  notify:
    - Restart IPSec

- name: Start IPSec
  service: name=ipsec state=started
  when: not (r1.changed or r2.changed or r3.changed or r4.changed)

- name: Auto-create a dedicated interface for IPSec
  copy: src=etc/network/if-up.d/ipsec
        dest=/etc/network/if-up.d/ipsec
        owner=root group=root
        mode=0755
  notify:
    - Reload networking

- name: Auto-deactivate the dedicated interface for IPSec
  file: src=../if-up.d/ipsec
        dest=/etc/network/if-down.d/ipsec
        owner=root group=root state=link force=yes

- meta: flush_handlers