ansible/roles/spiped/tasks/main.yaml

90 lines
2.2 KiB
YAML
Raw Permalink Normal View History

2020-01-23 14:00:57 +00:00
---
- name: install package
package:
name: "{{ spiped_package_name }}"
state: "{{ spiped_package_state }}"
- name: "create {{ spiped_user }} user"
user:
name: "{{ spiped_user }}"
comment: "{{ spiped_user_comment }}"
password: "{{ spiped_user_password }}"
home: "{{ spiped_user_home }}"
shell: "{{ spiped_user_shell }}"
state: "{{ spiped_user_state }}"
system: yes
create_home: no
- name: create paths
file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: 0755
loop:
- "{{ spiped_etc_path }}"
- name: configure systemd unit
template:
src: spiped.service.j2
dest: "/etc/systemd/system/spiped-{{ item.name }}.service"
owner: root
group: root
mode: 0644
loop: "{{ spiped_tunnels | default([]) }}"
2020-06-12 21:30:06 +00:00
when:
- ansible_service_mgr == 'systemd'
- item.state | default('present') == 'present'
2020-01-23 14:00:57 +00:00
notify:
- spiped daemon-reload
2020-06-12 21:30:06 +00:00
- restart spiped tunnels
2020-01-23 14:00:57 +00:00
no_log: true
- name: configure keys
copy:
dest: "{{ spiped_etc_path }}/{{ item.name }}.key"
content: "{{ item.key | b64decode }}"
owner: "{{ spiped_user }}"
group: "{{ spiped_group }}"
mode: 0400
loop: "{{ spiped_tunnels | default([]) }}"
2020-06-12 21:30:06 +00:00
when:
- ansible_service_mgr == 'systemd'
- item.state | default('present') == 'present'
2020-01-23 14:00:57 +00:00
notify:
- restart spiped tunnels
no_log: true
- name: manage services
2020-06-12 21:30:06 +00:00
systemd:
2020-01-23 14:00:57 +00:00
name: "spiped-{{ item.name }}.service"
2020-06-12 21:30:06 +00:00
state: "{{ (item.state | default('present') == 'absent') | ternary('stopped', 'started') }}"
enabled: "{{ item.state | default('present') != 'absent' }}"
daemon_reload: true
loop: "{{ spiped_tunnels | default([]) }}"
no_log: true
- name: remove keys
file:
path: "{{ spiped_etc_path }}/{{ item.name }}.key"
state: "absent"
2020-01-23 14:00:57 +00:00
loop: "{{ spiped_tunnels | default([]) }}"
2020-06-12 21:30:06 +00:00
when:
- item.state is defined
- item.state == "absent"
no_log: true
- name: remove systemd unit
file:
path: "/etc/systemd/system/spiped-{{ item.name }}.service"
state: "absent"
loop: "{{ spiped_tunnels | default([]) }}"
notify:
- spiped daemon-reload
when:
- ansible_service_mgr == 'systemd'
- item.state is defined
- item.state == "absent"
2020-01-23 14:00:57 +00:00
no_log: true