fix(hostname): resolve lints

This commit is contained in:
Jan Christian Grünhage 2022-09-02 12:48:20 +02:00
parent dd88cbb1ab
commit 8f2b50353a
No known key found for this signature in database
GPG key ID: EEC1170CE56FA2ED
4 changed files with 17 additions and 24 deletions

View file

@ -1,4 +1,2 @@
--- ---
hostname_extra_hosts: [] hostname_extra_hosts: []

View file

@ -1,42 +1,38 @@
--- ---
- name: Set /etc/hostname to FQDN of the server - name: Set /etc/hostname to FQDN of the server
copy: ansible.builtin.copy:
dest: /etc/hostname dest: /etc/hostname
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
content: | content: |
{{ hostname_fqdn }} {{ hostname_fqdn }}
tags: [ 'deploy', 'deploy-hostname' ] tags: [deploy, deploy-hostname]
- name: Ensure /etc/hosts contains all hostnames and aliases of the server - name: Ensure /etc/hosts contains all hostnames and aliases of the server
blockinfile: ansible.builtin.blockinfile:
dest: /etc/hosts dest: /etc/hosts
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
content: | content: |
{% for host in hostname_hosts %} {% for host in hostname_hosts %}
{{ host.ip }} {{ host.fqdn }} {{ host.alias | default([]) | join(" ") }} {{ host.ip }} {{ host.fqdn }} {{ host.alias | default([]) | join(" ") }}
{% endfor %} {% endfor %}
marker: "# {mark} ANSIBLE MANAGED BLOCK" marker: "# {mark} ANSIBLE MANAGED BLOCK"
tags: [ 'deploy', 'deploy-hostname' ] tags: [deploy, deploy-hostname]
# Needed because ansibles `ansible_fqdn` is loaded # Needed because ansibles `ansible_fqdn` is loaded
# from /etc/hostname, not from the running hostname # from /etc/hostname, not from the running hostname
- name: Query current hostname - name: Query current hostname
command: ansible.builtin.command:
cmd: "hostname" cmd: hostname
changed_when: false changed_when: false
check_mode: false check_mode: false
register: current_hostname register: current_hostname
tags: [ 'deploy', 'deploy-hostname' ] tags: [deploy, deploy-hostname]
- name: Set hostname via hostnamectl to avoid a reboot - name: Set hostname via hostnamectl to avoid a reboot
command: ansible.builtin.command:
cmd: "hostnamectl set-hostname {{ hostname_fqdn }}" cmd: hostnamectl set-hostname {{ hostname_fqdn }}
when: hostname_fqdn != hostname_current when: hostname_fqdn != hostname_current
vars: vars:
hostname_current: "{{ current_hostname.stdout }}." hostname_current: "{{ current_hostname.stdout }}."
tags: [ 'deploy', 'deploy-hostname' ] tags: [deploy, deploy-hostname]

View file

@ -1,7 +1,6 @@
--- ---
hostname_localhost: hostname_localhost:
ip: 127.0.0.1 ip: 127.0.0.1
fqdn: "localhost.localdomain" fqdn: localhost.localdomain
alias: [ "localhost" ] alias: [localhost]
hostname_hosts: "{{ [ hostname_localhost ] + hostname_extra_hosts }}" hostname_hosts: "{{ [hostname_localhost] + hostname_extra_hosts }}"

View file

@ -1,11 +1,11 @@
--- ---
- name: Ensure Pip is installed. - name: Ensure Pip is installed.
package: ansible.builtin.package:
name: "{{ pip_package_name }}" name: "{{ pip_package_name }}"
state: present state: present
- name: Install packages from list - name: Install packages from list
pip: ansible.builtin.pip:
name: "{{ item.name | default(item) }}" name: "{{ item.name | default(item) }}"
version: "{{ item.version | default(omit) }}" version: "{{ item.version | default(omit) }}"
virtualenv: "{{ item.virtualenv | default(omit) }}" virtualenv: "{{ item.virtualenv | default(omit) }}"
@ -16,7 +16,7 @@
environment: "{{ pip_environment_variables }}" environment: "{{ pip_environment_variables }}"
- name: Install packages from requirements file - name: Install packages from requirements file
pip: ansible.builtin.pip:
requirements: "{{ pip_requirements_file }}" requirements: "{{ pip_requirements_file }}"
virtualenv: "{{ pip_package_virtualenv | default(omit) }}" virtualenv: "{{ pip_package_virtualenv | default(omit) }}"
state: "{{ pip_package_state | default(omit) }}" state: "{{ pip_package_state | default(omit) }}"