xoxys.woodpecker_agent/tasks/instance.yml

50 lines
2.0 KiB
YAML
Raw Normal View History

2024-02-15 10:17:18 +00:00
---
- name: Register agent metadata
2024-02-19 09:15:45 +00:00
ansible.builtin.set_fact:
__woodpecker_agent_name: "{{ inst.name | regex_replace('[^a-z0-9]+', '-', ignorecase=True) }}"
2024-02-15 10:17:18 +00:00
__woodpecker_agent_volumes: "{{ inst.volumes | default(woodpecker_agent_volumes) }}"
__woodpecker_agent_cap_add: "{{ inst.cap_add | default(woodpecker_agent_cap_add) }}"
__woodpecker_agent_cap_drop: "{{ inst.cap_drop | default(woodpecker_agent_cap_drop) }}"
__woodpecker_agent_env: "{{ inst.env | default (woodpecker_agent_env) }}"
__woodpecker_agent_filter_labels: "{{ inst.filter_labels | default(woodpecker_agent_filter_labels) }}"
- name: Create container volumes
community.docker.docker_volume:
name: "{{ item.name }}"
driver_options: "{{ item.options | default(omit) }}"
state: "{{ item.state | default('present') }}"
loop: "{{ __woodpecker_agent_volumes }}"
loop_control:
label: "{{ item.name }}"
when: item.type | default("volume") | lower == "volume"
register: __woodpecker_agent_volumes_raw
- name: Register container volumes map
ansible.builtin.set_fact:
__woodpecker_agent_volumes_map: "{{ __woodpecker_agent_volumes_raw.results | json_query('[].volume') | items2dict(key_name='Name', value_name='Mountpoint') }}"
- name: Deploy env file
ansible.builtin.template:
src: etc/sysconfig/woodpecker_agent.j2
dest: "/etc/sysconfig/woodpecker-agent-{{ __woodpecker_agent_name }}"
owner: root
group: root
mode: "0600"
notify: __woodpecker_agent_restart
- name: Create container specs
ansible.builtin.template:
src: etc/systemd/system/woodpecker_agent.service.j2
dest: "/etc/systemd/system/woodpecker-agent-{{ __woodpecker_agent_name }}.service"
owner: root
group: root
mode: "0640"
notify: __woodpecker_agent_restart
- name: Ensure service state
ansible.builtin.service:
name: "woodpecker-agent-{{ __woodpecker_agent_name }}.service"
state: "{{ woodpecker_agent_service_started | ternary('started', 'stopped', 'started') }}"
daemon_reload: True
enabled: True