From 8f2b50353a3a4496dc2a49d3e73bb1a0c5def68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Fri, 2 Sep 2022 12:48:20 +0200 Subject: [PATCH] fix(hostname): resolve lints --- roles/hostname/defaults/main.yml | 2 -- roles/hostname/tasks/main.yml | 26 +++++++++++--------------- roles/hostname/vars/main.yml | 7 +++---- roles/pip/tasks/main.yml | 6 +++--- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/roles/hostname/defaults/main.yml b/roles/hostname/defaults/main.yml index 24b94d6..3be7cd9 100644 --- a/roles/hostname/defaults/main.yml +++ b/roles/hostname/defaults/main.yml @@ -1,4 +1,2 @@ --- - hostname_extra_hosts: [] - diff --git a/roles/hostname/tasks/main.yml b/roles/hostname/tasks/main.yml index bff78ba..b4df760 100644 --- a/roles/hostname/tasks/main.yml +++ b/roles/hostname/tasks/main.yml @@ -1,42 +1,38 @@ --- - - name: Set /etc/hostname to FQDN of the server - copy: + ansible.builtin.copy: dest: /etc/hostname owner: root group: root mode: 0644 content: | {{ hostname_fqdn }} - tags: [ 'deploy', 'deploy-hostname' ] - + tags: [deploy, deploy-hostname] - name: Ensure /etc/hosts contains all hostnames and aliases of the server - blockinfile: + ansible.builtin.blockinfile: dest: /etc/hosts owner: root group: root mode: 0644 content: | {% for host in hostname_hosts %} - {{ host.ip }} {{ host.fqdn }} {{ host.alias | default([]) | join(" ") }} + {{ host.ip }} {{ host.fqdn }} {{ host.alias | default([]) | join(" ") }} {% endfor %} marker: "# {mark} ANSIBLE MANAGED BLOCK" - tags: [ 'deploy', 'deploy-hostname' ] - + tags: [deploy, deploy-hostname] # Needed because ansibles `ansible_fqdn` is loaded # from /etc/hostname, not from the running hostname - name: Query current hostname - command: - cmd: "hostname" + ansible.builtin.command: + cmd: hostname changed_when: false check_mode: false register: current_hostname - tags: [ 'deploy', 'deploy-hostname' ] - + tags: [deploy, deploy-hostname] - name: Set hostname via hostnamectl to avoid a reboot - command: - cmd: "hostnamectl set-hostname {{ hostname_fqdn }}" + ansible.builtin.command: + cmd: hostnamectl set-hostname {{ hostname_fqdn }} when: hostname_fqdn != hostname_current vars: hostname_current: "{{ current_hostname.stdout }}." - tags: [ 'deploy', 'deploy-hostname' ] + tags: [deploy, deploy-hostname] diff --git a/roles/hostname/vars/main.yml b/roles/hostname/vars/main.yml index b7610a2..852c6fd 100644 --- a/roles/hostname/vars/main.yml +++ b/roles/hostname/vars/main.yml @@ -1,7 +1,6 @@ --- - hostname_localhost: ip: 127.0.0.1 - fqdn: "localhost.localdomain" - alias: [ "localhost" ] -hostname_hosts: "{{ [ hostname_localhost ] + hostname_extra_hosts }}" + fqdn: localhost.localdomain + alias: [localhost] +hostname_hosts: "{{ [hostname_localhost] + hostname_extra_hosts }}" diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 891fff0..2298b6b 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -1,11 +1,11 @@ --- - name: Ensure Pip is installed. - package: + ansible.builtin.package: name: "{{ pip_package_name }}" state: present - name: Install packages from list - pip: + ansible.builtin.pip: name: "{{ item.name | default(item) }}" version: "{{ item.version | default(omit) }}" virtualenv: "{{ item.virtualenv | default(omit) }}" @@ -16,7 +16,7 @@ environment: "{{ pip_environment_variables }}" - name: Install packages from requirements file - pip: + ansible.builtin.pip: requirements: "{{ pip_requirements_file }}" virtualenv: "{{ pip_package_virtualenv | default(omit) }}" state: "{{ pip_package_state | default(omit) }}"