---
- name: Create base config
copy:
dest: /tmp/{{ avahi_service_group.filename }}.service-tmp
content: |
changed_when: false
- name: Create service definition
file:
path: /etc/avahi/services/{{ avahi_service_group.filename }}.service
state: touch
modification_time: preserve
owner: root
group: root
mode: u=rw,g=r,o=r
changed_when: false
- name: Create base config
copy:
dest: /tmp/{{ avahi_service_group.filename }}.service-tmp
content: |
changed_when: false
- name: Set service name
community.general.xml:
path: /tmp/{{ avahi_service_group.filename }}.service-tmp
xpath: /service-group/name
value: "{{ avahi_service_group.name }}"
changed_when: false
- name: Set service attributes
community.general.xml:
path: /tmp/{{ avahi_service_group.filename }}.service-tmp
xpath: "/service-group/name"
value: "{{ item.value }}"
attribute: "{{ item.key }}"
loop: "{{ avahi_service_group.attributes | dict2items }}"
changed_when: false
- name: Add services
community.general.xml:
path: /tmp/{{ avahi_service_group.filename }}.service-tmp
xpath: "/service-group"
add_children:
- service:
protocol: "{{ item.protocol | default('any') }}"
_:
- type: "{{ item.type }}"
- port: "{{ item.port | default(0) }}"
loop: "{{ avahi_service_group.services }}"
changed_when: false
- name: Add service txt-records
community.general.xml:
path: /tmp/{{ avahi_service_group.filename }}.service-tmp
xpath: "/service-group/service[./type='{{ item.0.type }}']"
add_children:
- txt-record: "{{ item.1.value }}"
loop: "{{ avahi_service_group.services | subelements('txt-records', 'skip_missing=True') }}"
changed_when: false
- name: Add value format to txt-records
community.general.xml:
path: /tmp/{{ avahi_service_group.filename }}.service-tmp
xpath: "/service-group/service[./type='{{ item.0.type }}']/txt-record[text()='{{ item.1.value }}']"
attribute: value-format
value: "{{ item.1['value-format'] | default('text') }}"
loop: "{{ avahi_service_group.services | subelements('txt-records', 'skip_missing=True') }}"
changed_when: false
- stat:
path: "{{ item }}"
loop:
- "/tmp/{{ avahi_service_group.filename }}.service-tmp"
- "/etc/avahi/services/{{ avahi_service_group.filename }}.service"
register: avahi_service_group_stat
- ansible.builtin.copy:
src: "/tmp/{{ avahi_service_group.filename }}.service-tmp"
dest: "/etc/avahi/services/{{ avahi_service_group.filename }}.service"
mode: preserve
remote_src: true
when: avahi_service_group_stat.results[0].stat.checksum != avahi_service_group_stat.results[0].stat.checksum
notify: ["restart avahi"]