From db32a0016ce034f8a1f520954b5358abaeafbdc8 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Thu, 13 Feb 2025 09:41:06 +0100 Subject: [PATCH] Auto-fix usage of modules via FQCN Since ansible-core 2.10 it is recommended to use modules via FQCN In order to align with recommendation, we perform migration by applying suggestions made by `ansible-lint --fix=fqcn` Change-Id: Iaba6cf8e27e09d43f54f7fed66a6c19d93e5aa41 --- handlers/main.yml | 18 +++++++++--------- tasks/lxc_cache.yml | 12 ++++++------ tasks/lxc_cache_create.yml | 18 +++++++++--------- tasks/lxc_cache_preparation.yml | 16 ++++++++-------- tasks/lxc_cache_rootfs.yml | 12 ++++++------ tasks/lxc_install_apt.yml | 10 +++++----- tasks/lxc_install_dnf.yml | 18 +++++++++--------- tasks/lxc_net.yml | 14 +++++++------- tasks/lxc_post_install.yml | 12 ++++++------ tasks/lxc_pre_install.yml | 2 +- tasks/main.yml | 16 ++++++++-------- 11 files changed, 74 insertions(+), 74 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 5f8a95f8..8e4aa004 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -14,48 +14,48 @@ # limitations under the License. - name: Start apparmor - systemd: + ansible.builtin.systemd: name: "apparmor" enabled: true state: "started" - name: Reload apparmor - systemd: + ansible.builtin.systemd: name: "apparmor" state: "restarted" - name: Restart importd - systemd: + ansible.builtin.systemd: name: "systemd-importd.service" state: "restarted" - name: Restart irqbalance - systemd: + ansible.builtin.systemd: name: "irqbalance" state: "restarted" enabled: "yes" daemon_reload: true - name: Bring bridge up - command: "ip link set {{ lxc_net_bridge }} up" # noqa: no-changed-when + ansible.builtin.command: "ip link set {{ lxc_net_bridge }} up" # noqa: no-changed-when - name: Reload systemd units - systemd: + ansible.builtin.systemd: daemon_reload: true - name: Restart sshd - service: + ansible.builtin.service: name: sshd state: "restarted" enabled: true - name: Remove rootfs archive - file: + ansible.builtin.file: path: "/tmp/{{ cache_basename }}" state: "absent" - name: Restart dnsmasq - systemd: + ansible.builtin.systemd: name: "lxc-dnsmasq" state: "restarted" enabled: "yes" diff --git a/tasks/lxc_cache.yml b/tasks/lxc_cache.yml index 147951bb..0745dd85 100644 --- a/tasks/lxc_cache.yml +++ b/tasks/lxc_cache.yml @@ -14,7 +14,7 @@ # limitations under the License. - name: Set LXC cache fact(s) - set_fact: + ansible.builtin.set_fact: cache_path_fact: >- {{ lxc_container_cache_path ~ '/' ~ ansible_facts['distribution'] | lower ~ '/' ~ @@ -24,7 +24,7 @@ cache_time: "{{ now().timestamp() }}" - name: Retrieve the expiry object - slurp: + ansible.builtin.slurp: src: "{{ cache_path_fact }}/expiry" failed_when: false register: expiry @@ -34,7 +34,7 @@ - always - name: Set cache refresh fact - set_fact: + ansible.builtin.set_fact: lxc_image_cache_refresh: true when: - cache_time | int >= (expiry.content | default('MQo=') | b64decode | int) @@ -42,21 +42,21 @@ - always - name: Including lxc_cache_rootfs tasks - include_tasks: lxc_cache_rootfs.yml + ansible.builtin.include_tasks: lxc_cache_rootfs.yml when: - lxc_image_cache_refresh | bool tags: - lxc_hosts-config - name: Including lxc_cache_preparation tasks - include_tasks: lxc_cache_preparation.yml + ansible.builtin.include_tasks: lxc_cache_preparation.yml when: - lxc_image_cache_refresh | bool tags: - lxc_hosts-config - name: Including lxc_cache_create tasks - include_tasks: lxc_cache_create.yml + ansible.builtin.include_tasks: lxc_cache_create.yml when: - lxc_image_cache_refresh | bool tags: diff --git a/tasks/lxc_cache_create.yml b/tasks/lxc_cache_create.yml index baafd8c4..5ec1e770 100644 --- a/tasks/lxc_cache_create.yml +++ b/tasks/lxc_cache_create.yml @@ -14,20 +14,20 @@ # limitations under the License. - name: Create LXC cache dir - file: + ansible.builtin.file: path: "{{ cache_path_fact }}" state: "directory" recurse: true - name: Remove existing cache archive - file: + ansible.builtin.file: path: "{{ cache_path_fact }}/rootfs.tar.xz" state: "absent" # This is using a shell command because the ansible archive module does not # provide for the options needed to properly create an LXC image archive. - name: Create lxc image - shell: | + ansible.builtin.shell: | tar -Opc -C {{ lxc_image_cache_path }} . | {{ lxc_xz_bin }} -T 0 -{{ lxc_image_compression_ratio }} -c - > rootfs.tar.xz args: chdir: "{{ cache_path_fact }}/" @@ -35,7 +35,7 @@ - skip_ansible_lint - name: Drop container meta-data - template: + ansible.builtin.template: src: "meta-data/{{ item }}" dest: "{{ cache_path_fact }}/{{ item }}" owner: "root" @@ -49,19 +49,19 @@ - templates - name: Set expiry - copy: + ansible.builtin.copy: content: "{{ cache_time | int + lxc_image_cache_expiration | community.general.to_seconds | int }}" dest: "{{ cache_path_fact }}/expiry" mode: "0644" - name: Set build ID - copy: + ansible.builtin.copy: content: "{{ cache_time | int }}" dest: "{{ cache_path_fact }}/build_id" mode: "0644" - name: Create base container to use for containers with {{ lxc_container_backing_store }} - lxc_container: + community.general.lxc_container: name: "{{ lxc_container_base_name }}" template: "download" state: stopped @@ -78,7 +78,7 @@ - lxc_container_backing_store == 'btrfs' block: - name: Set the qgroup size|compression limits on machines - command: "btrfs qgroup limit {{ item }} /var/lib/lxc/{{ lxc_container_base_name }}" + ansible.builtin.command: "btrfs qgroup limit {{ item }} /var/lib/lxc/{{ lxc_container_base_name }}" changed_when: false with_items: - "-e {{ lxc_host_machine_qgroup_space_limit }}" @@ -87,7 +87,7 @@ - not lxc_host_machine_quota_disabled rescue: - name: Notice regarding quota system - debug: + ansible.builtin.debug: msg: >- There was an error processing the setup of qgroups. Check the system to ensure they're available otherwise disable the quota system by diff --git a/tasks/lxc_cache_preparation.yml b/tasks/lxc_cache_preparation.yml index 35787508..669d6f81 100644 --- a/tasks/lxc_cache_preparation.yml +++ b/tasks/lxc_cache_preparation.yml @@ -17,7 +17,7 @@ # to loop over a block. Re-evaluate this task when/if this is # merged https://github.com/ansible/ansible/issues/13262 - name: Rsyncing files from the LXC host to the container cache - shell: | + ansible.builtin.shell: | if [[ -e "{{ item }}" ]]; then rsync -av "{{ item }}" "{{ lxc_image_cache_path }}{{ item }}" else @@ -31,14 +31,14 @@ with_items: "{{ (_lxc_copy_from_host | union(lxc_container_cache_files_from_host)) | list }}" - name: Ensure directories exist for lxc_container_cache_files - file: + ansible.builtin.file: dest: "{{ lxc_image_cache_path }}{{ item.dest | default(item.src) | dirname }}" state: directory mode: "0755" with_items: "{{ lxc_container_cache_files }}" - name: Copy files from deployment host to the container cache - copy: + ansible.builtin.copy: src: "{{ item.src }}" dest: "{{ lxc_image_cache_path }}{{ item.dest | default(item.src) }}" owner: "{{ item.owner | default('root') }}" @@ -47,13 +47,13 @@ with_items: "{{ lxc_container_cache_files }}" - name: Ensure opt directory exists in container - file: + ansible.builtin.file: dest: "{{ lxc_image_cache_path }}/opt" state: directory mode: "0755" - name: Cached image preparation script - template: + ansible.builtin.template: src: "{{ lxc_cache_prep_template }}" dest: "{{ lxc_image_cache_path }}/opt/cache-prep-commands.sh" mode: "0755" @@ -61,7 +61,7 @@ # This task runs several commands against the cached image to speed up the # lxc_container_create playbook. - name: Prepare cached image setup commands - shell: "chroot {{ lxc_image_cache_path }} /opt/cache-prep-commands.sh > /var/log/lxc-cache-prep-commands.log 2>&1" + ansible.builtin.shell: "chroot {{ lxc_image_cache_path }} /opt/cache-prep-commands.sh > /var/log/lxc-cache-prep-commands.log 2>&1" changed_when: false async: "{{ lxc_cache_prep_timeout | int }}" poll: 0 @@ -70,7 +70,7 @@ # NOTE(cloudnull): Wait for the cache preparation script has completed before # building the new RootFS - name: Ensure that the LXC cache has been prepared - async_status: + ansible.builtin.async_status: jid: "{{ _lxc_cache_prepare_commands.ansible_job_id }}" register: _lxc_cache_prepare_commands_result until: _lxc_cache_prepare_commands_result.finished @@ -78,7 +78,7 @@ retries: "{{ lxc_cache_prep_timeout | int // 10 }}" - name: Remove requiretty for sudo on centos - template: + ansible.builtin.template: dest: "{{ lxc_image_cache_path }}/etc/sudoers.d/openstack-ansible" owner: root group: root diff --git a/tasks/lxc_cache_rootfs.yml b/tasks/lxc_cache_rootfs.yml index 5d534af9..20a760b0 100644 --- a/tasks/lxc_cache_rootfs.yml +++ b/tasks/lxc_cache_rootfs.yml @@ -14,20 +14,20 @@ # limitations under the License. - name: Create sparse machines file - command: "truncate -s 11G /var/lib/machines.raw" + ansible.builtin.command: "truncate -s 11G /var/lib/machines.raw" args: creates: /var/lib/machines.raw register: machines_create - name: Format the machines file - filesystem: + community.general.filesystem: fstype: ext4 dev: /var/lib/machines.raw when: - machines_create is changed - name: Create systemd mount - import_role: + ansible.builtin.import_role: name: systemd_mount vars: systemd_mounts: @@ -42,21 +42,21 @@ enabled: true - name: Remove the old image cache - file: + ansible.builtin.file: path: "/var/lib/machines/{{ lxc_container_base_name }}" state: absent when: - lxc_image_cache_refresh | bool - name: Create new image cache directory - file: + ansible.builtin.file: path: "/var/lib/machines/{{ lxc_container_base_name }}" state: directory mode: "0755" register: create_new_dir - name: Build the base image using a CLI tool - command: "{{ lxc_hosts_container_build_command }}" + ansible.builtin.command: "{{ lxc_hosts_container_build_command }}" when: lxc_hosts_container_build_command | length > 0 changed_when: false register: _build_container_base_image diff --git a/tasks/lxc_install_apt.yml b/tasks/lxc_install_apt.yml index 50bd09d6..67bcec17 100644 --- a/tasks/lxc_install_apt.yml +++ b/tasks/lxc_install_apt.yml @@ -14,7 +14,7 @@ # limitations under the License. - name: Remove conflicting packages - apt: + ansible.builtin.apt: pkg: "{{ lxc_hosts_remove_distro_packages }}" state: absent purge: true @@ -22,7 +22,7 @@ - lxc-apt-packages - name: Install apt packages - apt: + ansible.builtin.apt: pkg: "{{ lxc_hosts_distro_packages }}" state: "{{ lxc_hosts_package_state }}" default_release: "{{ lxc_default_release | default(omit) }}" @@ -37,7 +37,7 @@ - lxc-apt-packages - name: Drop irqbalance config - template: + ansible.builtin.template: src: "irqbalance.j2" dest: "{{ system_config_dir }}/irqbalance" owner: "root" @@ -51,7 +51,7 @@ - lxc_hosts-config - name: Drop lxc-openstack apparmor profile - template: + ansible.builtin.template: src: "lxc-openstack.apparmor.j2" dest: "/etc/apparmor.d/lxc/lxc-openstack" owner: "root" @@ -66,4 +66,4 @@ - lxc_hosts-config - name: Flush handler to reload apparmor profiles - meta: flush_handlers + ansible.builtin.meta: flush_handlers diff --git a/tasks/lxc_install_dnf.yml b/tasks/lxc_install_dnf.yml index 00e91965..0b0654f8 100644 --- a/tasks/lxc_install_dnf.yml +++ b/tasks/lxc_install_dnf.yml @@ -14,12 +14,12 @@ # limitations under the License. - name: Ensure createrepo package is installed - yum: + ansible.builtin.dnf: name: createrepo state: present - name: Deploy upstream COPR yum repo for lxc 3 - yum_repository: + ansible.builtin.yum_repository: name: thm-lxc3.0 description: "Copr repo for lxc3.0 owned by thm" baseurl: "{{ lxc_centos_package_baseurl }}" @@ -30,7 +30,7 @@ state: present - name: Add GPG key for COPR LXC repo - rpm_key: + ansible.builtin.rpm_key: key: "{{ lxc_centos_package_key }}" state: present register: add_keys @@ -39,7 +39,7 @@ delay: 2 - name: Download EPEL gpg keys - get_url: + ansible.builtin.get_url: url: "{{ lxc_centos_epel_key }}" dest: /etc/pki/rpm-gpg mode: "0640" @@ -49,12 +49,12 @@ delay: 2 - name: Install EPEL gpg keys - rpm_key: + ansible.builtin.rpm_key: key: "/etc/pki/rpm-gpg/{{ lxc_centos_epel_key.split('/')[-1] }}" state: present - name: Install the EPEL repository - Centos-8 - yum_repository: + ansible.builtin.yum_repository: name: epel-lxc_hosts baseurl: "{{ lxc_centos_epel_mirror ~ '/' ~ ansible_facts['distribution_major_version'] ~ '/Everything/' ~ ansible_facts['architecture'] }}" description: "Extra Packages for Enterprise Linux {{ ansible_facts['distribution_major_version'] }} - $basearch" @@ -69,7 +69,7 @@ delay: 2 - name: Install distro packages - package: + ansible.builtin.package: pkg: "{{ lxc_hosts_distro_packages }}" state: "{{ lxc_hosts_package_state }}" register: install_packages @@ -80,7 +80,7 @@ - lxc-packages - name: Remove sub system lock if found - file: + ansible.builtin.file: path: "/var/lock/subsys/lxc" state: "absent" owner: "root" @@ -89,7 +89,7 @@ - lxc-directories - name: Enable lxc service - service: + ansible.builtin.service: name: lxc enabled: "yes" tags: diff --git a/tasks/lxc_net.yml b/tasks/lxc_net.yml index 29801fe0..a8235d49 100644 --- a/tasks/lxc_net.yml +++ b/tasks/lxc_net.yml @@ -26,7 +26,7 @@ - skip_ansible_lint - name: Ensure network services wait on networking (if using NetworkManager) - service: + ansible.builtin.service: name: NetworkManager-wait-online.service enabled: true when: networkmanager_check.rc == 0 @@ -35,7 +35,7 @@ # and handle the customized LXC container networking. Starting lxc-net will # trample over these hooks and cause networking issues for containers. - name: Disable and stop lxc-net - systemd: + ansible.builtin.systemd: name: lxc-net enabled: false state: stopped @@ -44,14 +44,14 @@ - lxc-net - name: Setup LXC OVS Bridge - openvswitch_bridge: + openvswitch.openvswitch.openvswitch_bridge: bridge: "{{ lxc_net_bridge }}" fail_mode: standalone state: present when: lxc_net_bridge_type == 'openvswitch' - name: Run the systemd-networkd role - include_role: + ansible.builtin.include_role: name: systemd_networkd vars: _lxc_net_bridge_devices: @@ -76,7 +76,7 @@ Gateway: "{{ lxc_net_gateway is not none | ternary(lxc_net_gateway, {}) }}" - name: Run the systemd-service role - include_role: + ansible.builtin.include_role: name: systemd_service vars: systemd_service_enabled: true @@ -110,7 +110,7 @@ # Check that the container bridge exists, if not bring it up - name: Check Container Bridge exists - stat: + ansible.builtin.stat: path: "/sys/class/net/{{ lxc_net_bridge }}/bridge/bridge_id" register: bridge_check failed_when: false @@ -122,4 +122,4 @@ # Ensure lxc networks are running as they're supposed to - name: Flush handlers - meta: flush_handlers + ansible.builtin.meta: flush_handlers diff --git a/tasks/lxc_post_install.yml b/tasks/lxc_post_install.yml index 4fdf82c5..5ef9b223 100644 --- a/tasks/lxc_post_install.yml +++ b/tasks/lxc_post_install.yml @@ -14,7 +14,7 @@ # limitations under the License. - name: Ensure the lxc dnsmasq user exists - user: + ansible.builtin.user: name: "{{ lxc_net_dnsmasq_user }}" comment: "LXC dnsmasq" system: "yes" @@ -24,7 +24,7 @@ - lxc-dnsmasq-user - name: Drop base config file(s) - template: + ansible.builtin.template: src: "{{ item.src }}" dest: "{{ item.dest }}" owner: "{{ item.owner | default('root') }}" @@ -40,7 +40,7 @@ - lxc-config - name: Drop lxc veth check script - copy: + ansible.builtin.copy: src: "lxc-veth-check.sh" dest: "/usr/local/bin/lxc-veth-check" owner: "root" @@ -51,7 +51,7 @@ - lxc-config - name: Set systemd DefaultTasksMax value - lineinfile: + ansible.builtin.lineinfile: dest: /etc/systemd/system.conf state: present regexp: "^.*DefaultTasksMax.*$" @@ -64,7 +64,7 @@ - lxc-config - name: Set sshd MaxSessions - lineinfile: + ansible.builtin.lineinfile: dest: /etc/ssh/sshd_config state: present regexp: "^#?MaxSessions.*$" @@ -75,7 +75,7 @@ - lxc-config - name: Tuning kernel for lxc - sysctl: + ansible.posix.sysctl: name: "{{ item.key }}" value: "{{ item.value }}" sysctl_set: "{{ item.set | default('yes') }}" diff --git a/tasks/lxc_pre_install.yml b/tasks/lxc_pre_install.yml index 364b71a9..0de80f0b 100644 --- a/tasks/lxc_pre_install.yml +++ b/tasks/lxc_pre_install.yml @@ -14,7 +14,7 @@ # limitations under the License. - name: Create base directories - file: + ansible.builtin.file: path: "{{ item }}" state: "directory" owner: "root" diff --git a/tasks/main.yml b/tasks/main.yml index c93ca640..ae8727e8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,7 +14,7 @@ # limitations under the License. - name: Gather variables for each operating system - include_vars: "{{ lookup('first_found', params) }}" + ansible.builtin.include_vars: "{{ lookup('first_found', params) }}" vars: params: files: @@ -29,7 +29,7 @@ - always - name: Gather container variables - include_vars: "{{ lookup('first_found', params) }}" + ansible.builtin.include_vars: "{{ lookup('first_found', params) }}" vars: params: files: @@ -45,32 +45,32 @@ - always - name: Including lxc_pre_install tasks - include_tasks: lxc_pre_install.yml + ansible.builtin.include_tasks: lxc_pre_install.yml tags: - lxc_hosts-install - name: Including lxc_install tasks" - include_tasks: "lxc_install_{{ ansible_facts['pkg_mgr'] }}.yml" + ansible.builtin.include_tasks: "lxc_install_{{ ansible_facts['pkg_mgr'] }}.yml" tags: - lxc_hosts-install - name: Including lxc_post_install tasks - include_tasks: lxc_post_install.yml + ansible.builtin.include_tasks: lxc_post_install.yml tags: - lxc_hosts-config - name: Including lxc_net tasks - include_tasks: lxc_net.yml + ansible.builtin.include_tasks: lxc_net.yml when: - lxc_net_managed | bool tags: - lxc_hosts-config - name: Including lxc_cache tasks - include_tasks: lxc_cache.yml + ansible.builtin.include_tasks: lxc_cache.yml tags: - lxc_hosts-install - lxc_hosts-config - name: Flush handlers - meta: flush_handlers + ansible.builtin.meta: flush_handlers