|
43 | 43 | notify: |
44 | 44 | - restart libvirt |
45 | 45 |
|
| 46 | +- name: Create systemd drop-in directory for socket listen address |
| 47 | + file: |
| 48 | + path: "/etc/systemd/system/{{ item.service }}.d" |
| 49 | + state: directory |
| 50 | + owner: root |
| 51 | + group: root |
| 52 | + mode: 0755 |
| 53 | + become: true |
| 54 | + loop: "{{ _libvirt_socket_services | selectattr('enabled') }}" |
| 55 | + when: |
| 56 | + - item.listen_address is not none |
| 57 | + - item.listen_address | length > 0 |
| 58 | + loop_control: |
| 59 | + label: "{{ item.service }}" |
| 60 | + vars: |
| 61 | + _libvirt_listen_stream: "{{ item.listen_address }}" |
| 62 | + |
| 63 | +- name: Configure socket listen address |
| 64 | + template: |
| 65 | + src: socket.j2 |
| 66 | + dest: "/etc/systemd/system/{{ item.service }}.d/listen-address.conf" |
| 67 | + owner: root |
| 68 | + group: root |
| 69 | + mode: 0644 |
| 70 | + become: true |
| 71 | + loop: "{{ _libvirt_socket_services | selectattr('enabled') }}" |
| 72 | + when: |
| 73 | + - item.listen_address is not none |
| 74 | + - item.listen_address | length > 0 |
| 75 | + loop_control: |
| 76 | + label: "{{ item.service }}" |
| 77 | + vars: |
| 78 | + _libvirt_listen_stream: "{{ item.listen_address }}" |
| 79 | + notify: |
| 80 | + - reload systemd |
| 81 | + - restart libvirt |
| 82 | + |
| 83 | +- name: Create directory for TLS certificates and keys |
| 84 | + file: |
| 85 | + path: "{{ item }}" |
| 86 | + state: directory |
| 87 | + owner: root |
| 88 | + group: root |
| 89 | + mode: 0700 |
| 90 | + become: true |
| 91 | + loop: >- |
| 92 | + {{ _libvirt_tls_certs.values() | |
| 93 | + selectattr('content') | |
| 94 | + map(attribute='dest') | |
| 95 | + map('dirname') | |
| 96 | + unique }} |
| 97 | + when: |
| 98 | + - libvirt_host_tls_listen | bool |
| 99 | + |
| 100 | +- name: Copy TLS certificates and keys |
| 101 | + copy: |
| 102 | + content: "{{ _libvirt_loop_item.content }}" |
| 103 | + dest: "{{ _libvirt_loop_item.dest }}" |
| 104 | + owner: root |
| 105 | + group: root |
| 106 | + mode: "{{ _libvirt_loop_item.mode }}" |
| 107 | + become: true |
| 108 | + # NOTE: Loop over keys of _libvirt_tls_certs to avoid leaking the key |
| 109 | + # contents. |
| 110 | + loop: "{{ _libvirt_tls_certs.keys() }}" |
| 111 | + when: |
| 112 | + - libvirt_host_tls_listen | bool |
| 113 | + - _libvirt_loop_item.content |
| 114 | + vars: |
| 115 | + _libvirt_loop_item: "{{ _libvirt_tls_certs[item] }}" |
| 116 | + notify: restart libvirt |
| 117 | + |
46 | 118 | - name: Flush handlers |
47 | 119 | meta: flush_handlers |
48 | 120 |
|
49 | 121 | - name: Ensure the libvirt daemon is started and enabled |
50 | 122 | service: |
51 | | - name: libvirtd |
52 | | - state: started |
53 | | - enabled: yes |
| 123 | + name: "{{ item.service }}" |
| 124 | + state: "{{ item.enabled | bool | ternary('started', 'stopped') }}" |
| 125 | + enabled: "{{ item.enabled | bool }}" |
54 | 126 | become: True |
| 127 | + loop: "{{ _libvirt_services }}" |
| 128 | + loop_control: |
| 129 | + label: "{{ item.service }}" |
| 130 | + vars: |
| 131 | + _libvirt_services: |
| 132 | + - service: libvirtd-tcp.socket |
| 133 | + enabled: "{{ libvirt_host_tcp_listen | bool }}" |
| 134 | + - service: libvirtd-tls.socket |
| 135 | + enabled: "{{ libvirt_host_tls_listen | bool }}" |
| 136 | + - service: libvirtd |
| 137 | + enabled: true |
0 commit comments