blob: dd661b03a70ce603432d514a3388ea92a95b1599 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
---
- name: Create base config
copy:
dest: /tmp/{{ avahi_service_group.filename }}.service-tmp
content: |
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
</service-group>
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: |
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
</service-group>
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"]
|