Execution
Date
08 Dec 2025 13:40:18 +0000
Duration
00:10:06.79
Controller
aio1.openstack.local
User
root
Versions
Ansible
2.18.6
ara
1.7.4 / 1.7.4
Python
3.12.11
Summary
15
Hosts
608
Tasks
2412
Results
18
Plays
158
Files
0
Records
File: /home/zuul/src/opendev.org/openstack/openstack-ansible-lxc_container_create/tasks/lxc_container_config.yml
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | --- # Copyright 2014, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # CONTAINER SETUP AND CONFIG - name: Write default container config ansible.builtin.lineinfile: dest: "/var/lib/lxc/{{ inventory_hostname }}/config" line: "{{ item.split('=', 1)[0] }} = {{ item.split('=', 1)[1] }}" backup: "true" with_items: "{{ lxc_container_default_config_list | union(lxc_container_config_list) }}" delegate_to: "{{ physical_host }}" register: default_configuration_container notify: - Lxc container restart - name: Ensure containers have required auto mounts ansible.builtin.lineinfile: dest: "/var/lib/lxc/{{ inventory_hostname }}/config" line: "lxc.mount.auto = {{ lxc_container_mount_auto | join(' ') }}" regexp: "^lxc.mount.auto =" backup: "true" delegate_to: "{{ physical_host }}" - name: Ensure bind mount host directories exists ansible.builtin.file: path: "{{ item['host_directory'] }}" state: "directory" mode: "0755" with_items: "{{ lxc_container_default_bind_mounts | union(_lxc_container_bind_mounts) | union(lxc_container_bind_mounts) }}" delegate_to: "{{ physical_host }}" - name: Add bind mount configuration to container ansible.builtin.lineinfile: dest: "/var/lib/lxc/{{ inventory_hostname }}/config" line: "lxc.mount.entry = {{ item['host_directory'] }} {{ item['container_directory'].lstrip('/') }} none bind,create=dir 0 0" backup: "true" with_items: "{{ lxc_container_default_bind_mounts | union(_lxc_container_bind_mounts) | union(lxc_container_bind_mounts) }}" delegate_to: "{{ physical_host }}" register: bind_configuration_container notify: - Lxc container restart - name: Create and start the container community.general.lxc_container: name: "{{ inventory_hostname }}" state: started delegate_to: "{{ physical_host }}" - name: Gather container facts ansible.builtin.setup: gather_subset: "!all" - name: Drop container setup script ansible.builtin.template: src: "container-setup.sh.j2" dest: "/opt/container-setup.sh" owner: "root" group: "root" mode: "0755" - name: Drop container first run script ansible.builtin.template: src: "container-first-run.sh.j2" dest: "/var/lib/lxc/{{ inventory_hostname }}/container-first-run.sh" owner: "root" group: "root" mode: "0755" delegate_to: "{{ physical_host }}" - name: Execute first script ansible.builtin.command: "/var/lib/lxc/{{ inventory_hostname }}/container-first-run.sh" args: creates: "/var/lib/lxc/{{ inventory_hostname }}/setup.complete" register: container_extra_commands until: container_extra_commands is success retries: 5 delay: 2 delegate_to: "{{ physical_host }}" # CONTAINER SETUP AND CONFIG # VETH AND CONNECTIVITY SETTINGS - name: Create container mac script ansible.builtin.template: src: container_mac_generation.sh.j2 dest: "/var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}_mac_generation.sh" mode: "0755" delegate_to: "{{ physical_host }}" with_dict: "{{ lxc_container_networks_combined }}" # TODO(noondeadpunk): Remove that in X cycle - name: Cleanup old mac scripts ansible.builtin.file: path: "/openstack/{{ inventory_hostname }}/{{ item.value.interface }}_mac_generation.sh" state: absent delegate_to: "{{ physical_host }}" with_dict: "{{ lxc_container_networks_combined }}" - name: Set define static mac address from an existing interface ansible.builtin.command: "/var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}_mac_generation.sh" args: creates: "/var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.hwaddr" delegate_to: "{{ physical_host }}" with_dict: "{{ lxc_container_networks_combined }}" - name: Gather hardware addresses to be used as facts ansible.builtin.slurp: src: "/var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.hwaddr" changed_when: false register: macs with_dict: "{{ lxc_container_networks_combined }}" delegate_to: "{{ physical_host }}" # NOTE(cloudnull): To dynamically set the mac address "facts" Ansible line # format is being used - name: Set fixed hardware address fact ansible.builtin.set_fact: "{{ item.item.value.interface }}_mac_address={{ item.content | b64decode }}" # noqa: no-free-form with_items: - "{{ macs.results }}" # NOTE(andymccr): We need an index for the interfaces in LXC >= 3 converting # to a list and using with_indexed_items for this purpose. - name: LXC host config for container networks ansible.builtin.template: src: "container-interface.ini.j2" dest: "/var/lib/lxc/{{ inventory_hostname }}/{{ item.1.interface }}.ini" owner: "root" group: "root" mode: "0644" with_indexed_items: "{{ (lxc_container_networks_combined.values() | list) | sort(attribute='interface') }}" register: network_config delegate_to: "{{ physical_host }}" - name: Container network includes ansible.builtin.lineinfile: dest: "/var/lib/lxc/{{ inventory_hostname }}/config" line: "lxc.include = /var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.ini" backup: "true" with_dict: "{{ lxc_container_networks_combined }}" when: item.value.interface is defined register: network_includes delegate_to: "{{ physical_host }}" - name: Create wiring script ansible.builtin.copy: src: "lxc-veth-wiring.sh" dest: "/var/lib/lxc/{{ inventory_hostname }}/lxc-veth-wiring.sh" owner: "root" group: "root" mode: "0755" delegate_to: "{{ physical_host }}" # Adds post-down and pre-start hooks - name: Drop veth cleanup script ansible.builtin.template: src: "veth-cleanup.sh.j2" dest: "/var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh" owner: "root" group: "root" mode: "0755" delegate_to: "{{ physical_host }}" - name: Defines a pre, post, and haltsignal configs ansible.builtin.lineinfile: dest: "/var/lib/lxc/{{ inventory_hostname }}/config" line: "{{ item }}" backup: "true" with_items: - "lxc.hook.pre-start = /var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh" - "lxc.hook.post-stop = /var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh" - "lxc.signal.halt = SIGRTMIN+4" delegate_to: "{{ physical_host }}" - name: Run veth wiring ansible.builtin.set_fact: lxc_container_veth_wiring: true when: - ((not lxc_container_veth_wiring | bool) and ((network_config is changed) and (network_includes is changed))) and not ((default_configuration_container is changed) or (bind_configuration_container is changed)) - name: Run container veth wiring script ansible.builtin.command: >- /var/lib/lxc/{{ inventory_hostname }}/lxc-veth-wiring.sh "{{ inventory_hostname }}" "{{ lxc_container_network_veth_pair[-15:] }}" "{{ item.value.interface }}" "{{ item.value.bridge }}" "{{ item.value.bridge_type | default('linux_bridge') }}" register: wiring_script with_dict: "{{ lxc_container_networks_combined }}" when: - lxc_container_veth_wiring | bool - item.value.interface is defined - item.value.type is not defined or item.value.type == 'veth' failed_when: wiring_script.rc not in [3, 0] changed_when: wiring_script.rc == 3 delegate_to: "{{ physical_host }}" - name: Including lxc_container_network tasks ansible.builtin.include_tasks: "lxc_container_network.yml" # VETH AND CONNECTIVITY SETTINGS # SYSTEMD SERVICES - name: Run the systemd-service role ansible.builtin.import_role: name: systemd_service vars: systemd_service_enabled: true systemd_slice_name: lxc-system systemd_services: "{{ _lxc_container_systemd_services }}" # SYSTEMD SERVICES # ENVIRONMENT AND HOSTNAME SETTINGS - name: Add global_environment_variables to environment file ansible.builtin.blockinfile: dest: "/etc/environment" state: present marker: "# {mark} Managed by OpenStack-Ansible" insertbefore: EOF block: "{{ lookup('template', 'environment.j2') }}" remote_user: root - name: Create localhost config ansible.builtin.lineinfile: dest: "/etc/hosts" regexp: "^127.0.0.1" line: "127.0.0.1 localhost" owner: "root" group: "root" mode: "0644" remote_user: root - name: Set hostnamectl name ansible.builtin.command: "/usr/bin/hostnamectl --static --pretty --transient set-hostname {{ intended_hostname }}" changed_when: false vars: intended_hostname: "{{ inventory_hostname | replace('_', '-') | quote }}" when: ansible_facts['hostname'] != intended_hostname - name: Generate machine-id ansible.builtin.command: "systemd-machine-id-setup" args: creates: "/etc/machine-id" register: machine_id notify: - Lxc container restart - name: Ensure the dbus directory exists ansible.builtin.file: path: "/var/lib/dbus" state: "directory" mode: "0755" - name: Create dbus machine-id ansible.builtin.copy: src: "/etc/machine-id" dest: "/var/lib/dbus/machine-id" mode: "0444" remote_src: "yes" remote_user: root - name: Link container journal to host block: - name: Retrieve the machine-id ansible.builtin.slurp: src: /etc/machine-id register: machine_id - name: Set bind mount for journal linking ansible.builtin.set_fact: lxc_container_journal_path: "/var/log/journal/{{ (machine_id.content | b64decode).strip() }}" - name: Ensure journal directory exists ansible.builtin.file: path: "{{ lxc_container_journal_path }}" state: "directory" group: "systemd-journal" owner: "root" mode: "02755" delegate_to: "{{ item }}" with_items: - "{{ physical_host }}" - "{{ inventory_hostname }}" - name: Add bind mount configuration to container ansible.builtin.lineinfile: dest: "/var/lib/lxc/{{ inventory_hostname }}/config" line: "lxc.mount.entry = {{ lxc_container_journal_path }} {{ lxc_container_journal_path.lstrip('/') }} none bind,create=dir 0 0" backup: "true" delegate_to: "{{ physical_host }}" when: - lxc_container_journal_link | bool # ENVIRONMENT AND HOSTNAME SETTINGS # SET CONTAINER FACTS - name: Allow the usage of local facts ansible.builtin.file: path: /etc/ansible/facts.d/ state: directory mode: "0755" tags: - always - name: Record the container variant deployed community.general.ini_file: dest: "/etc/ansible/facts.d/openstack_ansible.fact" section: lxc option: variant value: "{{ properties['lxc_container_variant'] | default(lxc_container_variant) }}" mode: "0644" tags: - always # SET CONTAINER FACTS |