From 28d0fee303d48333aac7f4e00cfeb9e13c3d1b58 Mon Sep 17 00:00:00 2001 From: Norman Ziegner Date: Mon, 18 Aug 2025 10:27:39 +0200 Subject: [PATCH] keepalived role: prefix all internal variables with two underscores Signed-off-by: Norman Ziegner --- roles/keepalived/handlers/main.yml | 4 +-- roles/keepalived/tasks/main.yml | 50 ++++++++++++++++-------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/roles/keepalived/handlers/main.yml b/roles/keepalived/handlers/main.yml index dd446d45..6eda6745 100644 --- a/roles/keepalived/handlers/main.yml +++ b/roles/keepalived/handlers/main.yml @@ -11,7 +11,7 @@ name: "keepalived" state: "restarted" daemon_reload: true - when: "not initial_dry_run" + when: "not __initial_dry_run" - name: "Reload Keepalived" become: true @@ -19,6 +19,6 @@ name: "keepalived" state: "reloaded" daemon_reload: true - when: "not initial_dry_run" + when: "not __initial_dry_run" ... diff --git a/roles/keepalived/tasks/main.yml b/roles/keepalived/tasks/main.yml index 988a07e8..e40ba664 100644 --- a/roles/keepalived/tasks/main.yml +++ b/roles/keepalived/tasks/main.yml @@ -32,37 +32,39 @@ - name: "Check whether Keepalived binary is installed." ansible.builtin.stat: path: "{{ keepalived_executable_path }}" - register: "keepalived_installed" + register: "__keepalived_binary" - name: "Determine if this is an initial dry-run" ansible.builtin.set_fact: - initial_dry_run: "{{ ansible_check_mode and not keepalived_installed.stat.exists }}" + __initial_dry_run: "{{ ansible_check_mode and not __keepalived_binary.stat.exists }}" - name: "Get Keepalived version." ansible.builtin.command: cmd: "{{ keepalived_executable_path }} --version" - register: "keepalived_version_installed" - when: "keepalived_installed.stat.exists" + register: "__keepalived_version_installed" + when: "__keepalived_binary.stat.exists" changed_when: false check_mode: false - name: "Put value of installed version into an Ansible fact." ansible.builtin.set_fact: - installed_keepalived_version: "{{ keepalived_version_installed.stderr | regex_search('^Keepalived v(\\d+\\.\\d+\\.\\d+)', '\\1') | first }}" - when: "keepalived_installed.stat.exists" + __installed_keepalived_version: "{{ __keepalived_version_installed.stderr | regex_search('^Keepalived v(\\d+\\.\\d+\\.\\d+)', '\\1') | first }}" + when: "__keepalived_binary.stat.exists" - name: "Output version strings of installed and to be installed Keepalived." ansible.builtin.debug: - msg: "Installed version: {{ installed_keepalived_version }}, version to be installed: {{ keepalived_version }}." - when: "installed_keepalived_version is defined" + msg: "Installed version: {{ __installed_keepalived_version }}, version to be installed: {{ keepalived_version }}." + when: "__installed_keepalived_version is defined" - name: "Check if both version strings are equal." ansible.builtin.set_fact: - is_keepalived_version_equal: "{{ installed_keepalived_version is version(keepalived_version, operator='==', strict=True) }}" - when: "keepalived_installed.stat.exists" + __is_keepalived_version_equal: "{{ __installed_keepalived_version is version(keepalived_version, operator='==', strict=True) }}" + when: "__keepalived_binary.stat.exists" - name: "Continue with installing Keepalived if Keepalived is not already installed or versions are not equal." - when: "not keepalived_installed.stat.exists or not is_keepalived_version_equal" + when: >- + not __keepalived_binary.stat.exists or + not __is_keepalived_version_equal block: - name: "Create temporary Keepalived build directory." @@ -70,18 +72,18 @@ ansible.builtin.tempfile: state: "directory" prefix: "keepalived-{{ keepalived_version }}_" - register: "tempdir" + register: "__tempdir" check_mode: false - name: "Store temporary build directory path" ansible.builtin.set_fact: - keepalived_build_dir: "{{ tempdir.path }}" + __keepalived_build_dir: "{{ __tempdir.path }}" - name: "Download and extract keepalived archive." become: true ansible.builtin.unarchive: src: "{{ keepalived_download_url }}" - dest: "{{ keepalived_build_dir }}" + dest: "{{ __keepalived_build_dir }}" remote_src: true extra_opts: - "--strip-components=1" @@ -93,27 +95,27 @@ become: true ansible.builtin.command: "./configure" args: - chdir: "{{ keepalived_build_dir }}" + chdir: "{{ __keepalived_build_dir }}" changed_when: true - name: "Build Keepalived from source." become: true community.general.make: - chdir: "{{ keepalived_build_dir }}" - when: "not initial_dry_run" + chdir: "{{ __keepalived_build_dir }}" + when: "not __initial_dry_run" - name: "Install Keepalived binaries." become: true community.general.make: - chdir: "{{ keepalived_build_dir }}" + chdir: "{{ __keepalived_build_dir }}" target: "install" notify: "Restart Keepalived" - when: "not initial_dry_run" + when: "not __initial_dry_run" - name: "Copy Keepalived sysconfig file" become: true ansible.builtin.copy: - src: "{{ keepalived_build_dir }}/keepalived/etc/sysconfig/keepalived" + src: "{{ __keepalived_build_dir }}/keepalived/etc/sysconfig/keepalived" dest: "{{ keepalived_sysconfig_file_path }}" owner: "root" group: "root" @@ -124,7 +126,7 @@ - name: "Remove temporary build directory" become: true ansible.builtin.file: - path: "{{ keepalived_build_dir }}" + path: "{{ __keepalived_build_dir }}" state: "absent" check_mode: false @@ -142,8 +144,8 @@ become: true ansible.builtin.command: cmd: "{{ keepalived_executable_path | quote }} --config-test --use-file {{ keepalived_conf_file_path | quote }}" - register: "config_check" - changed_when: "config_check.rc != 0" + register: "__config_check" + changed_when: "__config_check.rc != 0" - name: "Create Keepalived Service Unit File." ansible.builtin.template: @@ -161,6 +163,6 @@ state: "started" enabled: true daemon_reload: true - when: "not initial_dry_run" + when: "not __initial_dry_run" ...