Skip to content

Commit 9248b51

Browse files
authored
Merge pull request #468 from Normo/haproxy-internal-vars
haproxy role: prefix all internal variables with two underscores
2 parents 52cedfa + 9232dcf commit 9248b51

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

roles/haproxy/handlers/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
- name: "Check HAProxy configuration file"
99
ansible.builtin.command:
1010
cmd: "{{ haproxy_executable_path }} -c -q -f {{ haproxy_conf_file_path }}"
11-
register: "check_haproxy_config"
12-
changed_when: "check_haproxy_config.rc != 0"
13-
failed_when: "check_haproxy_config.rc != 0"
11+
register: "__check_haproxy_config"
12+
changed_when: false
13+
failed_when: "__check_haproxy_config.rc != 0"
1414

1515
- name: "Restart HAProxy"
1616
become: true
1717
ansible.builtin.service:
1818
name: "{{ haproxy_name }}"
1919
state: "restarted"
20-
ignore_errors: "{{ ignore_errors_in_check_mode }}" # noqa ignore-errors
20+
ignore_errors: "{{ __ignore_errors_in_check_mode }}" # noqa ignore-errors
2121

2222
- name: "Reload HAProxy"
2323
become: true
2424
ansible.builtin.service:
2525
name: "{{ haproxy_name }}"
2626
state: "reloaded"
27-
ignore_errors: "{{ ignore_errors_in_check_mode }}" # noqa ignore-errors
27+
ignore_errors: "{{ __ignore_errors_in_check_mode }}" # noqa ignore-errors
2828

2929
...

roles/haproxy/tasks/main.yml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
signed_by: "https://haproxy.debian.net/bernat.debian.org.gpg"
6565
state: "present"
6666
enabled: true
67-
register: "deb_repo"
67+
register: "__deb_repo"
6868

6969
- name: "Add PPA for HAProxy"
7070
when:
@@ -76,54 +76,57 @@
7676
state: "present"
7777
validate_certs: true
7878
mode: "0644"
79-
register: "ppa"
79+
register: "__ppa"
8080

8181
- name: "Check whether wildcard character is contained in version string."
8282
ansible.builtin.set_fact:
83-
version_contains_wildcard: "{{ '*' in haproxy_version }}"
83+
__version_contains_wildcard: "{{ '*' in haproxy_version }}"
8484

8585
- name: "Check whether HAProxy binary is installed."
8686
ansible.builtin.stat:
8787
path: "{{ haproxy_executable_path }}"
88-
register: "haproxy_installed"
88+
register: "__haproxy_binary"
8989

9090
- name: "Check currently installed HAProxy version"
91-
when: "not version_contains_wildcard and haproxy_installed.stat.exists"
91+
when:
92+
- "not __version_contains_wildcard"
93+
- "__haproxy_binary.stat.exists"
9294
block:
9395
- name: "Get HAProxy version."
9496
ansible.builtin.command:
9597
cmd: "{{ haproxy_executable_path }} -v"
96-
register: "haproxy_version_installed"
98+
register: "__haproxy_version_installed"
9799
changed_when: false
98100
check_mode: false
99101

100102
- name: "Extract installed and target HAProxy versions."
101103
ansible.builtin.set_fact:
102-
installed_version: "{{ haproxy_version_installed |
104+
__installed_version: "{{ __haproxy_version_installed |
103105
regex_search('HA-?Proxy version (\\d+\\.\\d+\\.\\d+)', '\\1') |
104106
default([None], True) |
105107
first }}"
106-
target_version: "{{ haproxy_version |
108+
__target_version: "{{ haproxy_version |
107109
regex_search('^(\\d+\\.\\d+\\.\\d+)', '\\1') |
108110
default([None], True) |
109111
first }}"
110112

111113
- name: "Determine if errors in check mode can be ignored"
112114
ansible.builtin.set_fact:
113-
ignore_errors_in_check_mode: "{{ ansible_check_mode and (ppa.changed or deb_repo.changed) }}"
115+
__ignore_errors_in_check_mode: "{{ ansible_check_mode and (__ppa.changed or __deb_repo.changed) }}"
114116

115117
- name: "Install and configure HAProxy"
116-
ignore_errors: "{{ ignore_errors_in_check_mode }}" # noqa ignore-errors
118+
ignore_errors: "{{ __ignore_errors_in_check_mode }}" # noqa ignore-errors
117119
block:
118120

119121
- name: "Install or upgrade haproxy package."
120122
become: true
121123
ansible.builtin.package:
122124
name: "{{ haproxy_name }}={{ haproxy_version }}"
123125
update_cache: true
124-
when: "version_contains_wildcard or
125-
not haproxy_installed.stat.exists or
126-
installed_version is version(target_version, operator='lt', strict=True)"
126+
when: >-
127+
__version_contains_wildcard or
128+
not __haproxy_binary.stat.exists or
129+
__installed_version is version(__target_version, operator='lt', strict=True)
127130
128131
- name: "Create HAProxy Configuration Directory."
129132
become: true
@@ -157,7 +160,7 @@
157160

158161
- name: "Generate self-signed TLS certificate"
159162
when: "haproxy_create_self_signed_cert | bool"
160-
ignore_errors: "{{ ignore_errors_in_check_mode }}" # noqa ignore-errors
163+
ignore_errors: "{{ __ignore_errors_in_check_mode }}" # noqa ignore-errors
161164
block:
162165
- name: "Generate an OpenSSL Private Key (4096 bits)"
163166
become: true
@@ -227,7 +230,7 @@
227230
- "Reload HAProxy"
228231

229232
- name: "Generate DH Parameter file"
230-
ignore_errors: "{{ ignore_errors_in_check_mode }}" # noqa ignore-errors
233+
ignore_errors: "{{ __ignore_errors_in_check_mode }}" # noqa ignore-errors
231234
become: true
232235
community.crypto.openssl_dhparam:
233236
path: "{{ haproxy_ssl_dhparam_file }}"

0 commit comments

Comments
 (0)