Ansible roles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.9 KiB

---
- name: Install packages
yum:
name:
- seadrive
- fuse
- name: Ensure fuse is loaded
modprobe: name=fuse state=present
- name: Create global directories
file: path={{ item }} state=directory mode=755
with_items:
- /etc/seadrive
- /var/cache/seadrive
- name: Create cache directories
file: path={{ item.data_dir | default('/var/cache/seadrive/' + item.id) }} state=directory owner={{ item.user | default('root') }} mode=700
with_items: "{{ seadrive_daemons }}"
- name: Create drive directories
file: path={{ item.drive_dir }} state=directory owner={{ item.user | default('root') }} mode=700
with_items: "{{ seadrive_daemons }}"
ignore_errors: True # Needed if allow_other is not set as root can't check the mount point
- name: Make sure allow_other is available for user
lineinfile: dest=/etc/fuse.conf regexp='^user_allow_other' line='user_allow_other'
- name: List existing instances
shell: ls /etc/systemd/system/seadrive-*.service | perl -ne 's/.*\/seadrive\-(.*)\.service/$1/ && print "$1\n"'
register: seadrive_instances
changed_when: False
- name: List managed instances
set_fact: seadrive_managed_instances={{ seadrive_daemons | map(attribute='id') | list }}
- name: List instances to be removed
set_fact: seadrive_remove_instances={{ seadrive_instances.stdout_lines | difference(seadrive_managed_instances) }}
- name: Stop unmanaged instances
service: name=seadrive-{{ item }} state=stopped enabled=False
with_items: "{{ seadrive_remove_instances }}"
- name: Remove unmanaged instances
file: path=/etc/systemd/system/seadrive-{{ item }}.service state=absent
with_items: "{{ seadrive_remove_instances }}"
register: seadrive_remove_units
- name: Remove unmanaged config
file: path=/etc/seadrive/{{ item }}.conf state=absent
with_items: "{{ seadrive_remove_instances }}"
- name: Remove unmanaged cache directories
file: path=/var/cache/seadrive/{{ item }} state=absent
with_items: "{{ seadrive_remove_instances }}"
- name: Obtain API Tokens
uri:
url: "{{ item.server }}/api2/auth-token/"
method: POST
body: "username={{ item.login }}&password={{ item.pass }}"
return_content: True
register: seadrive_tokens
when: item.token is not defined
with_items: "{{ seadrive_daemons }}"
- name: Deploy systemd units
template: src=seadrive.service.j2 dest=/etc/systemd/system/seadrive-{{ item.id }}.service
with_items: "{{ seadrive_daemons }}"
register: seadrive_new_units
notify: restart seadrive
- name: Deploy configurations
template: src=seadrive.conf.j2 dest=/etc/seadrive/{{ item.id }}.conf owner={{ item.user | default('root') }} mode=600
with_items: "{{ seadrive_daemons }}"
notify: restart seadrive
- name: Reload systemd
command: systemctl daemon-reload
when: seadrive_new_units.changed or seadrive_remove_units.changed
- name: Start and enable managed instances
service: name=seadrive-{{ item.id }} state=started enabled=yes
with_items: "{{ seadrive_daemons }}"