REFACTOR: files fixed according to ansible-lint

This commit is contained in:
2026-07-12 15:36:55 +00:00
parent 9a9bfa7e23
commit d1568586e9
8 changed files with 69 additions and 58 deletions
@@ -1,7 +1,7 @@
--- ---
- name: Create a new user with a password, set shell - name: Create a new user with a password, set shell
remote_user: ansible remote_user: ansible
user: ansible.builtin.user:
name: max name: max
groups: sshusers,sudo groups: sshusers,sudo
password: "{{ user_passwd_hash }}" password: "{{ user_passwd_hash }}"
@@ -16,8 +16,8 @@
- name: Copy omz installation wrapper script to the target machine - name: Copy omz installation wrapper script to the target machine
remote_user: ansible remote_user: ansible
copy: ansible.builtin.copy:
src: ../files/install_omz.sh src: "{{ role_path }}/files/install_omz.sh"
dest: /home/max/install_omz.sh dest: /home/max/install_omz.sh
owner: max owner: max
group: max group: max
@@ -26,13 +26,14 @@
# WARNING: UNPRIVILEGED USER (not ansible) COMMANDS # WARNING: UNPRIVILEGED USER (not ansible) COMMANDS
- name: Install oh my zsh - name: Install oh my zsh
remote_user: max remote_user: max
become: no become: false
command: /home/max/install_omz.sh ansible.builtin.command: /home/max/install_omz.sh
changed_when: true
- name: Configure oh my zsh, by pushing the config file - name: Configure oh my zsh, by pushing the config file
remote_user: ansible remote_user: ansible
copy: ansible.builtin.copy:
src: ../files/.zshrc src: "{{ role_path }}/files/.zshrc"
dest: /home/max/.zshrc dest: /home/max/.zshrc
owner: max owner: max
group: max group: max
@@ -40,8 +41,8 @@
- name: Configure vim, by pushing the config - name: Configure vim, by pushing the config
remote_user: ansible remote_user: ansible
copy: ansible.builtin.copy:
src: ../files/.vimrc src: "{{ role_path }}/files/.vimrc"
dest: /home/max/.vimrc dest: /home/max/.vimrc
owner: max owner: max
group: max group: max
@@ -3,18 +3,18 @@
- name: Install sudo on apt systems - name: Install sudo on apt systems
when: (ansible_facts['distribution'] == "Debian") or when: (ansible_facts['distribution'] == "Debian") or
(ansible_facts['distribution'] == "Ubuntu") (ansible_facts['distribution'] == "Ubuntu")
apt: ansible.builtin.apt:
name: name:
- sudo - sudo
update-cache: yes update-cache: true
- name: Update Alpine packages # The same commands for Alpine
- name: Update and install packages on Alpine
when: (ansible_facts['distribution'] == "Alpine") when: (ansible_facts['distribution'] == "Alpine")
command: /sbin/apk update community.general.apk:
name: sudo
- name: Install sudo package on Alpine update_cache: true
when: (ansible_facts['distribution'] == "Alpine") remote_user: ansible
command: /sbin/apk add sudo
## Creating and setting up the ansible user ## Creating and setting up the ansible user
@@ -26,12 +26,12 @@
## Add the user to sshusers (for ssh access) and sudo (gain root access) ## Add the user to sshusers (for ssh access) and sudo (gain root access)
- name: Create a new user with a password for Ansible - name: Create a new user with a password for Ansible
user: ansible.builtin.user:
name: ansible name: ansible
password: "{{ ansible_user_passwd_hash }}" password: "{{ ansible_user_passwd_hash }}"
groups: sshusers,sudo groups: sshusers,sudo
append: yes append: true
## Since password authentication in SSH will be disabled, we need to add an authorized key ## Since password authentication in SSH will be disabled, we need to add an authorized key
- name: Set authorized key taken from file - name: Set authorized key taken from file
@@ -4,11 +4,11 @@
remote_user: ansible remote_user: ansible
when: (ansible_facts['distribution'] == "Debian") or when: (ansible_facts['distribution'] == "Debian") or
(ansible_facts['distribution'] == "Ubuntu") (ansible_facts['distribution'] == "Ubuntu")
apt: ansible.builtin.apt:
name: name:
- nano - nano
state: absent state: absent
become: yes become: true
# Clean up all orphaned packages # Clean up all orphaned packages
@@ -16,12 +16,16 @@
remote_user: ansible remote_user: ansible
when: (ansible_facts['distribution'] == "Debian") or when: (ansible_facts['distribution'] == "Debian") or
(ansible_facts['distribution'] == "Ubuntu") (ansible_facts['distribution'] == "Ubuntu")
apt: ansible.builtin.apt:
autoremove: yes autoremove: true
purge: yes purge: true
- name: Install sudo package on Alpine - name: Install sudo package on Alpine
remote_user: ansible remote_user: ansible
when: (ansible_facts['distribution'] == "Alpine") when: (ansible_facts['distribution'] == "Alpine")
command: /sbin/apk del nano community.general.apk:
name:
- nano
state: absent
become: true
@@ -1,6 +1,6 @@
--- ---
- name: Generate locales - name: Generate locales
ansible.builtin.locale_gen: community.general.locale_gen:
name: name:
- en_US.UTF-8 - en_US.UTF-8
- ru_RU.UTF-8 - ru_RU.UTF-8
@@ -15,5 +15,5 @@
LC_ALL=en_US.UTF-8 LC_ALL=en_US.UTF-8
- name: Set time - name: Set time
ansible.builtin.timezone: community.general.timezone:
name: Europe/Samara name: Europe/Samara
+19 -13
View File
@@ -2,14 +2,14 @@
- name: Internet connection test block - name: Internet connection test block
block: block:
- name: Test reachability to ya.ru - name: Test reachability to ya.ru
become: yes # Usually it's not necessary, but sometimes there are some wierd issues with ping, especially on Alpine become: true # Usually it's not necessary, but sometimes there are some wierd issues with ping, especially on Alpine
shell: ping -c 5 ya.ru > /dev/null ansible.builtin.shell: ping -c 5 ya.ru > /dev/null
changed_when: false # This task does not change the system changed_when: false # This task does not change the system
rescue: rescue:
# This won't work for now. CA certificate reissuing is required!git # This won't work for now. CA certificate reissuing is required!
- name: Create a test file - name: Create a test file
become: no become: false
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ ha_addr }}/api/webhook/{{ ha_webhook_token }}" url: "{{ ha_addr }}/api/webhook/{{ ha_webhook_token }}"
ca_path: ../files/ca.pem ca_path: ../files/ca.pem
@@ -20,19 +20,25 @@
- name: Disk free space test block - name: Disk free space test block
block: block:
- name: Test free disk space in root - name: Test free disk space in root
become: no become: false
shell: df -h / | tail -1 | awk '{gsub(/%/, "", $5); print $5}' ansible.builtin.shell: set -o pipefail && df -h / | tail -1 | awk '{gsub(/%/, "", $5); print $5}'
register: result register: common_healthcheck_result
failed_when: result.stdout | int > 85 failed_when: common_healthcheck_result.stdout | int > 1
changed_when: false # This task does not change the system changed_when: false # This task does not change the system
rescue: rescue:
- name: Notify with ntfy - name: Notify with ntfy
become: no become: false
ansible.builtin.command: | ansible.builtin.uri:
curl -H "Authorization: Bearer {{ ntfy_topic_token }}" \ url: "{{ ntfy_topic }}"
-d "{{ ansible_facts['hostname'] }}: Disk space is low" \ method: POST
{{ ntfy_topic }} body_format: json
status_code: [200, 202]
return_content: true
headers:
Authorization: "Bearer {{ ntfy_topic_token }}"
body:
- "{{ ansible_facts['hostname'] }}: Disk space is low"
delegate_to: 127.0.0.1 delegate_to: 127.0.0.1
failed_when: false failed_when: false
changed_when: false # This task does not change the system changed_when: false # This task does not change the system