From cb87bbc690d8a5dfbef973930f2b2c2fe764a38f Mon Sep 17 00:00:00 2001 From: Khue Doan Date: Sat, 14 May 2022 21:24:39 +0700 Subject: [PATCH] style(metal): fix Ansible lint --- .tekton/pipeline.yaml | 1 + metal/group_vars/all.yml | 2 +- metal/roles/automatic_upgrade/tasks/main.yml | 6 ++--- metal/roles/k3s/tasks/main.yml | 23 ++++++++++---------- metal/roles/pxe_server/tasks/main.yml | 13 ++++++----- metal/roles/wake/tasks/main.yml | 2 +- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.tekton/pipeline.yaml b/.tekton/pipeline.yaml index f19dc785..637a39d8 100644 --- a/.tekton/pipeline.yaml +++ b/.tekton/pipeline.yaml @@ -57,6 +57,7 @@ spec: - ansible-lint args: - -v + - --force-color - name: yaml command: - yamllint diff --git a/metal/group_vars/all.yml b/metal/group_vars/all.yml index 8828020b..39fb7737 100644 --- a/metal/group_vars/all.yml +++ b/metal/group_vars/all.yml @@ -1,4 +1,4 @@ ansible_user: root ansible_ssh_private_key_file: ~/.ssh/id_ed25519 -ssh_public_key: "{{lookup('file', '~/.ssh/id_ed25519.pub') }}" +ssh_public_key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}" dns_server: "8.8.8.8" diff --git a/metal/roles/automatic_upgrade/tasks/main.yml b/metal/roles/automatic_upgrade/tasks/main.yml index 037976e1..e8242c80 100644 --- a/metal/roles/automatic_upgrade/tasks/main.yml +++ b/metal/roles/automatic_upgrade/tasks/main.yml @@ -1,17 +1,17 @@ - name: Install packages for automatic upgrade - dnf: + ansible.builtin.dnf: name: - dnf-automatic - dnf-utils - name: Copy automatic upgrade config file - copy: + ansible.builtin.copy: src: automatic.conf dest: /etc/dnf/automatic.conf mode: 0644 - name: Enable automatic upgrade service - systemd: + ansible.builtin.systemd: name: dnf-automatic.timer state: started enabled: true diff --git a/metal/roles/k3s/tasks/main.yml b/metal/roles/k3s/tasks/main.yml index d30550e9..5e53b708 100644 --- a/metal/roles/k3s/tasks/main.yml +++ b/metal/roles/k3s/tasks/main.yml @@ -1,14 +1,15 @@ - name: Download k3s binary - get_url: + ansible.builtin.get_url: url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-amd64.txt dest: "{{ role_path }}/files/bin/k3s" + mode: 0755 delegate_to: localhost run_once: true register: k3s_binary - name: Copy k3s binary to nodes - copy: + ansible.builtin.copy: src: bin/k3s dest: /usr/local/bin/k3s owner: root @@ -16,7 +17,7 @@ mode: 0755 - name: Ensure config directories exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0755 @@ -26,32 +27,32 @@ - name: Check if k3s token file exists on the first node run_once: true - stat: + ansible.builtin.stat: path: "{{ k3s_token_file }}" register: k3s_token_file_stat - name: Generate k3s token file on the first node if not exist yet run_once: true when: not k3s_token_file_stat.stat.exists - copy: + ansible.builtin.copy: content: "{{ lookup('community.general.random_string', length=32) }}" dest: "{{ k3s_token_file }}" mode: 0600 - name: Get k3s token from the first node run_once: true - slurp: + ansible.builtin.slurp: src: "{{ k3s_token_file }}" register: k3s_token_base64 - name: Ensure all nodes has the same token - copy: + ansible.builtin.copy: content: "{{ k3s_token_base64.content | b64decode }}" dest: "{{ k3s_token_file }}" mode: 0600 - name: Copy k3s config files - template: + ansible.builtin.template: src: "{{ item.src }}" dest: "{{ item.dest }}" mode: 0644 @@ -62,7 +63,7 @@ dest: "{{ k3s_service_file }}" - name: Enable k3s service - systemd: + ansible.builtin.systemd: name: k3s enabled: true state: started @@ -72,12 +73,12 @@ - name: Get Kubernetes config file run_once: true - slurp: + ansible.builtin.slurp: src: /etc/rancher/k3s/k3s.yaml register: kubeconfig_base64 - name: Write Kubernetes config file with the correct cluster address - copy: + ansible.builtin.copy: content: "{{ kubeconfig_base64.content | b64decode | replace('127.0.0.1', hostvars[groups['masters'][0]].ansible_host) }}" dest: "{{ playbook_dir }}/kubeconfig.yaml" mode: 0600 diff --git a/metal/roles/pxe_server/tasks/main.yml b/metal/roles/pxe_server/tasks/main.yml index dd9fdf2a..ddebbafa 100644 --- a/metal/roles/pxe_server/tasks/main.yml +++ b/metal/roles/pxe_server/tasks/main.yml @@ -1,36 +1,37 @@ - name: Download boot image - get_url: + ansible.builtin.get_url: url: "{{ iso_url }}" dest: "{{ role_path }}/files/data/iso/{{ iso_url | basename }}" checksum: "{{ iso_checksum }}" + mode: 0644 register: iso - name: Extract boot image - command: + ansible.builtin.command: cmd: "xorriso -osirrox on -indev {{ iso.dest }} -extract / {{ role_path }}/files/data/os" creates: "{{ role_path }}/files/data/os/.treeinfo" - name: Generate DHCP config - template: + ansible.builtin.template: src: dhcpd.conf.j2 dest: "{{ role_path }}/files/data/pxe-config/dhcpd.conf" mode: 0644 - name: Generate GRUB config - template: + ansible.builtin.template: src: grub.cfg.j2 dest: "{{ role_path }}/files/data/pxe-config/grub.cfg" mode: 0644 - name: Generate init config for each machine - template: + ansible.builtin.template: src: kickstart.ks.j2 dest: "{{ role_path }}/files/data/init-config/{{ hostvars[item]['mac'] }}.ks" mode: 0644 loop: "{{ groups['metal'] }}" - name: Start the ephemeral PXE server - docker_compose: + community.docker.docker_compose: project_src: "{{ role_path }}/files" state: present restarted: true diff --git a/metal/roles/wake/tasks/main.yml b/metal/roles/wake/tasks/main.yml index 2a2a0191..6e90561a 100644 --- a/metal/roles/wake/tasks/main.yml +++ b/metal/roles/wake/tasks/main.yml @@ -4,5 +4,5 @@ delegate_to: localhost - name: Wait for the machines to come online - wait_for_connection: + ansible.builtin.wait_for_connection: timeout: 600