Skip to content

Commit

Permalink
Add a cleanup component
Browse files Browse the repository at this point in the history
  • Loading branch information
tjheeta committed Feb 13, 2015
1 parent e8f40cb commit bebab73
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 69 deletions.
11 changes: 11 additions & 0 deletions tasks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# TODO: this doesn't seem to shutdown correctly
- service: name=tinc state=stopped

- name: "Cleanup hosts file"
lineinfile: dest=/etc/hosts regexp='.*\.{{ tinc_netname }}$' state=absent

- file: path=/etc/tinc/{{ tinc_netname }}/ state=absent mode=0755

- lineinfile: dest="/etc/tinc/nets.boot" line="{{ tinc_netname }}" state=absent

73 changes: 4 additions & 69 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,8 @@
---
- apt: name={{ item }} state=installed
with_items:
- runit
- tinc
- rsync
when: ansible_os_family == 'Debian'

- file: path=/etc/tinc/{{ tinc_netname }}/hosts state=directory mode=0755 recurse=true
- shell: tincd -n {{ tinc_netname }} -K4096
args:
creates: "/etc/tinc/{{ tinc_netname }}/rsa_key.priv"
- include: setup.yml
when: tinc_state == "present"

- file: path={{ tinc_tmpdir }}/{{ tinc_netname }}/pubkeys state=directory recurse=true
delegate_to: localhost
sudo: false
- file: path={{ tinc_tmpdir }}/{{ tinc_netname }}/ip state=directory recurse=true
delegate_to: localhost
sudo: false
- file: path={{ tinc_tmpdir }}/{{ tinc_netname }}/current state=directory recurse=true
delegate_to: localhost
sudo: false
- include: cleanup.yml
when: tinc_state == "absent"

- fetch: src=/etc/tinc/{{ tinc_netname }}/ansible_ipaddress dest={{ tinc_tmpdir }}/{{ tinc_netname }}/ip/{{ ansible_hostname }} flat=yes
ignore_errors: yes

- fetch: src=/etc/tinc/{{ tinc_netname }}/rsa_key.pub dest={{ tinc_tmpdir }}/{{ tinc_netname }}/pubkeys/{{ ansible_hostname }} flat=yes
ignore_errors: yes

# Set an ipaddress for each host in set if they don't have already
- script: setip.py {{ tinc_tmpdir }}/{{ tinc_netname }}/pubkeys {{ tinc_tmpdir }}/{{ tinc_netname }}/ip {{ tinc_subnet }}
tags: test
register: ip_output
delegate_to: localhost

- debug: var=ip_output
tags: test

- template: src=host_configuration.j2 dest="{{ tinc_tmpdir }}/{{ tinc_netname }}/current/{{ ansible_hostname }}"
tags: test
delegate_to: localhost

- template: src=tinc.conf.j2 dest="/etc/tinc/{{ tinc_netname }}/tinc.conf" mode=0644
notify: restart_tinc

- template: src=tinc-up.j2 dest="/etc/tinc/{{ tinc_netname }}/tinc-up" mode=0755
notify: restart_tinc

- template: src=tinc-down.j2 dest="/etc/tinc/{{ tinc_netname }}/tinc-down" mode=0755
notify: restart_tinc

- copy: src="{{ tinc_tmpdir}}/{{ tinc_netname }}/ip/{{ ansible_hostname }}" dest="/etc/tinc/{{ tinc_netname }}/ansible_ipaddress"

- copy: src="{{ tinc_tmpdir }}/{{ tinc_netname }}/current/" dest="/etc/tinc/{{ tinc_netname }}/hosts/"
notify: restart_tinc

- lineinfile: dest="/etc/tinc/nets.boot" line="{{ tinc_netname }}" state=present
notify: restart_tinc

- service: name=tinc state=started

# The facts aren't available on first run, so copy over all the ip addresses
- file: path=/etc/tinc/{{ tinc_netname }}/tmp state=directory mode=0755 recurse=true
- copy: src="{{ tinc_tmpdir}}/{{ tinc_netname }}/ip/" dest="/etc/tinc/{{ tinc_netname }}/tmp"

- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item | basename}}.{{ tinc_netname }}$' line="{{ lookup('file', item) }} {{ item | basename }}.{{ tinc_netname }}" state=present
with_fileglob:
- "/etc/tinc/{{ tinc_netname }}/tmp/*"
tags: hostsfile

- file: dest="{{ tinc_tmpdir }}/{{ tinc_netname }}" state=absent
delegate_to: localhost
73 changes: 73 additions & 0 deletions tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
- apt: name={{ item }} state=installed
with_items:
- runit
- tinc
- rsync
when: ansible_os_family == 'Debian'

- file: path=/etc/tinc/{{ tinc_netname }}/hosts state=directory mode=0755 recurse=true
- shell: tincd -n {{ tinc_netname }} -K4096
args:
creates: "/etc/tinc/{{ tinc_netname }}/rsa_key.priv"

- file: path={{ tinc_tmpdir }}/{{ tinc_netname }}/pubkeys state=directory recurse=true
delegate_to: localhost
sudo: false
- file: path={{ tinc_tmpdir }}/{{ tinc_netname }}/ip state=directory recurse=true
delegate_to: localhost
sudo: false
- file: path={{ tinc_tmpdir }}/{{ tinc_netname }}/current state=directory recurse=true
delegate_to: localhost
sudo: false

- fetch: src=/etc/tinc/{{ tinc_netname }}/ansible_ipaddress dest={{ tinc_tmpdir }}/{{ tinc_netname }}/ip/{{ ansible_hostname }} flat=yes
ignore_errors: yes

- fetch: src=/etc/tinc/{{ tinc_netname }}/rsa_key.pub dest={{ tinc_tmpdir }}/{{ tinc_netname }}/pubkeys/{{ ansible_hostname }} flat=yes
ignore_errors: yes

# Set an ipaddress for each host in set if they don't have already
- script: setip.py {{ tinc_tmpdir }}/{{ tinc_netname }}/pubkeys {{ tinc_tmpdir }}/{{ tinc_netname }}/ip {{ tinc_subnet }}
tags: test
register: ip_output
delegate_to: localhost

- debug: var=ip_output
tags: test

- template: src=host_configuration.j2 dest="{{ tinc_tmpdir }}/{{ tinc_netname }}/current/{{ ansible_hostname }}"
tags: test
delegate_to: localhost

- template: src=tinc.conf.j2 dest="/etc/tinc/{{ tinc_netname }}/tinc.conf" mode=0644
notify: restart_tinc

- template: src=tinc-up.j2 dest="/etc/tinc/{{ tinc_netname }}/tinc-up" mode=0755
notify: restart_tinc

- template: src=tinc-down.j2 dest="/etc/tinc/{{ tinc_netname }}/tinc-down" mode=0755
notify: restart_tinc

- copy: src="{{ tinc_tmpdir}}/{{ tinc_netname }}/ip/{{ ansible_hostname }}" dest="/etc/tinc/{{ tinc_netname }}/ansible_ipaddress"

- copy: src="{{ tinc_tmpdir }}/{{ tinc_netname }}/current/" dest="/etc/tinc/{{ tinc_netname }}/hosts/"
notify: restart_tinc

- lineinfile: dest="/etc/tinc/nets.boot" line="{{ tinc_netname }}" state=present
notify: restart_tinc

- service: name=tinc state=started

# The facts aren't available on first run, so copy over all the ip addresses
- file: path=/etc/tinc/{{ tinc_netname }}/tmp state=directory mode=0755 recurse=true
- copy: src="{{ tinc_tmpdir}}/{{ tinc_netname }}/ip/" dest="/etc/tinc/{{ tinc_netname }}/tmp"

- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item | basename}}.{{ tinc_netname }}$' line="{{ lookup('file', item) }} {{ item | basename }}.{{ tinc_netname }}" state=present
with_fileglob:
- "/etc/tinc/{{ tinc_netname }}/tmp/*"
tags: hostsfile

- file: dest="{{ tinc_tmpdir }}/{{ tinc_netname }}" state=absent
delegate_to: localhost

0 comments on commit bebab73

Please sign in to comment.