diff --git a/defaults/main.yml b/defaults/main.yml index c8b3a5c..4c06389 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -164,7 +164,7 @@ lxc_container_enable_resolved: true # "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}-container.yml" # or by providing the full path to a local file containing all of the variables # needed to prepare a container. -#lxc_user_defined_container: null +# lxc_user_defined_container: null # Dictionary of settings for containers properties: {} diff --git a/handlers/main.yml b/handlers/main.yml index ceac231..6aa79fa 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -43,6 +43,7 @@ --logfile {{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log --logpriority {{ (debug | bool) | ternary('DEBUG', 'INFO') }} delegate_to: "{{ physical_host }}" + changed_when: false register: container_start until: container_start is success retries: 3 diff --git a/meta/main.yml b/meta/main.yml index cd392b0..5bd855a 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -18,19 +18,21 @@ galaxy_info: description: Create an LXC container company: Rackspace license: Apache2 - min_ansible_version: 2.4 + min_ansible_version: "2.10" + role_name: lxc_containers_create + namespace: openstack platforms: - name: Debian versions: - - buster + - bullseye - name: Ubuntu versions: - - bionic - focal + - jammy - name: EL versions: - - 8 - categories: + - "9" + galaxy_tags: - cloud - lxc - container diff --git a/tasks/lxc_container_config.yml b/tasks/lxc_container_config.yml index aefdf1a..08c5401 100644 --- a/tasks/lxc_container_config.yml +++ b/tasks/lxc_container_config.yml @@ -38,6 +38,7 @@ 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 }}" @@ -126,7 +127,7 @@ # NOTE(cloudnull): To dynamically set the mac address "facts" Ansible line # format is being used - name: Set fixed hardware address fact - set_fact: "{{ item.item.value.interface }}_mac_address={{ item.content | b64decode }}" + set_fact: "{{ item.item.value.interface }}_mac_address={{ item.content | b64decode }}" # noqa: no-free-form with_items: - "{{ macs.results }}" @@ -210,7 +211,8 @@ changed_when: wiring_script.rc == 3 delegate_to: "{{ physical_host }}" -- include_tasks: "lxc_container_network.yml" +- name: Including lxc_container_network tasks + include_tasks: "lxc_container_network.yml" # VETH AND CONNECTIVITY SETTINGS @@ -263,6 +265,7 @@ file: path: "/var/lib/dbus" state: "directory" + mode: "0755" - name: Create dbus machine-id copy: @@ -310,6 +313,7 @@ file: path: /etc/ansible/facts.d/ state: directory + mode: "0755" tags: - always @@ -319,6 +323,7 @@ section: lxc option: variant value: "{{ properties['lxc_container_variant'] | default(lxc_container_variant) }}" + mode: "0644" tags: - always # SET CONTAINER FACTS diff --git a/tasks/lxc_container_create.yml b/tasks/lxc_container_create.yml index a73ba46..fbf8971 100644 --- a/tasks/lxc_container_create.yml +++ b/tasks/lxc_container_create.yml @@ -17,6 +17,7 @@ file: path: "{{ item }}" state: "directory" + mode: "0755" with_items: - "/openstack/{{ inventory_hostname }}" - "/openstack/backup/{{ inventory_hostname }}" @@ -34,7 +35,8 @@ delegate_to: "{{ physical_host }}" # Run the lxc container creation process based on the backend store type -- include_tasks: "lxc_container_create_{{ lxc_container_backing_store }}.yml" +- name: "Including lxc_container_create tasks for {{ lxc_container_backing_store }}" + include_tasks: "lxc_container_create_{{ lxc_container_backing_store }}.yml" - name: Check container state command: "lxc-info -n {{ inventory_hostname }} --state" @@ -58,6 +60,7 @@ delegate_to: "{{ physical_host }}" register: _lxc_container_create until: _lxc_container_create is success + changed_when: false retries: 3 delay: 5 when: diff --git a/tasks/lxc_container_create_cow.yml b/tasks/lxc_container_create_cow.yml index c3c03d6..21af8e9 100644 --- a/tasks/lxc_container_create_cow.yml +++ b/tasks/lxc_container_create_cow.yml @@ -37,6 +37,7 @@ --logfile {{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log --logpriority {{ (debug | bool) | ternary('DEBUG', 'INFO') }} delegate_to: "{{ physical_host }}" + changed_when: false when: - lxc_container_info.rc != 0 diff --git a/tasks/lxc_container_create_lvm.yml b/tasks/lxc_container_create_lvm.yml index ee78234..1190d13 100644 --- a/tasks/lxc_container_create_lvm.yml +++ b/tasks/lxc_container_create_lvm.yml @@ -31,6 +31,7 @@ - lxc_container_backing_store == 'lvm' - lxc_container_backing_method != 'copy-on-write' -- include_tasks: lxc_container_create_cow.yml +- name: Including lxc_container_create_cow tasks + include_tasks: lxc_container_create_cow.yml when: - lxc_container_backing_method == 'copy-on-write' diff --git a/tasks/main.yml b/tasks/main.yml index 7f35bea..4fdea57 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,6 +18,7 @@ file: path: /etc/ansible/facts.d/ state: directory + mode: "0755" delegate_to: "{{ physical_host }}" tags: - always @@ -39,38 +40,42 @@ # NOTE(cloudnull): Check for the LXC volume group when creating LVM backed # containers. -- block: - - name: Check for lxc volume group - shell: "(which vgs > /dev/null && vgs | grep -o '{{ lxc_container_vg_name }}') || false" - register: vg_result - failed_when: false - changed_when: vg_result.rc != 0 - delegate_to: "{{ physical_host }}" - - name: LXC VG check - fail: - msg: >- - The "lxc_container_backing_store" option was set to "lvm" but no LXC - volume group was found on the physical host. Please check your settings - and host setup. - when: - - vg_result.rc != 0 +- name: Verify LVM VG + block: + - name: Check for lxc volume group + shell: "(which vgs > /dev/null && vgs | grep -o '{{ lxc_container_vg_name }}') || false" + register: vg_result + failed_when: false + changed_when: vg_result.rc != 0 + delegate_to: "{{ physical_host }}" + - name: LXC VG check + fail: + msg: >- + The "lxc_container_backing_store" option was set to "lvm" but no LXC + volume group was found on the physical host. Please check your settings + and host setup. + when: + - vg_result.rc != 0 when: - lxc_container_backing_store == 'lvm' tags: - always -- include_tasks: lxc_container_destroy.yml +- name: Including lxc_container_destroy tasks + include_tasks: lxc_container_destroy.yml when: - physical_host != inventory_hostname - lxc_container_recreate | bool -- include_tasks: lxc_container_create.yml +- name: Including lxc_container_create tasks + include_tasks: lxc_container_create.yml when: - physical_host != inventory_hostname tags: - lxc-create -- include_tasks: lxc_container_config.yml +- name: Including lxc_container_config tasks + include_tasks: lxc_container_config.yml when: - physical_host != inventory_hostname tags: diff --git a/vars/main.yml b/vars/main.yml index 6a3f645..4fc7568 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -15,7 +15,7 @@ lxc_container_map: distro: "{{ hostvars[physical_host]['ansible_facts']['distribution'] | lower }}" - arch: "{{ lxc_architecture_mapping.get( hostvars[physical_host]['ansible_facts']['architecture'] | lower ) }}" + arch: "{{ lxc_architecture_mapping.get(hostvars[physical_host]['ansible_facts']['architecture'] | lower) }}" release: "{{ hostvars[physical_host]['ansible_facts']['distribution_major_version'] }}" lxc_container_default_config_list: