Skip to content

Commit

Permalink
Fix linter for Consul (#370)
Browse files Browse the repository at this point in the history
* 🔥 chore(ansible-lint.yml): remove ../roles/consul from exclude_paths
The ../roles/consul path was previously excluded from ansible-lint checks, but it is no longer necessary as the issue it was addressing has been resolved.

* 🎨 style(consul): change variable name from `consul_autopilot_cleanup_dead_Servers` to `consul_autopilot_cleanup_dead_servers` for consistency
The variable name `consul_autopilot_cleanup_dead_Servers` has been changed to `consul_autopilot_cleanup_dead_servers` to improve consistency with the naming conventions used in the rest of the codebase.

* 🐛 fix(dnsmasq.yml): remove unnecessary jinja2 brackets in when statement
The jinja2 brackets in the when statement are unnecessary and can be removed. This commit removes them to improve readability and consistency with other tasks in the playbook.

* 🐛 fix(encrypt_gossip.yml): add pipefail option to shell command to prevent silent errors
The `set -o pipefail` option was added to the shell command to prevent silent errors that may occur when the `grep` command fails to find the "encrypt" key in the `config.json` file. This ensures that any errors that occur during the execution of the command are caught and reported.
  • Loading branch information
ThomasSanson authored Jun 10, 2023
1 parent 7c1237a commit 6f4fe12
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion .config/ansible-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ skip_list:
- yaml[truthy]

exclude_paths:
- ../roles/consul/ # TODO - https://github.com/ansible-community/ansible-consul/pull/520
- ../.venv
# https://ansible-lint.readthedocs.io/configuring/
# https://ansible-lint.readthedocs.io/rules/
2 changes: 1 addition & 1 deletion roles/consul/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ https://www.consul.io/docs/guides/autopilot.html
- Override with `CONSUL_AUTOPILOT_ENABLE` environment variable
- Default value: false

#### `consul_autopilot_cleanup_dead_Servers`
#### `consul_autopilot_cleanup_dead_servers`

Dead servers will periodically be cleaned up and removed from the Raft peer set, to prevent them from interfering with the quorum size and leader elections. This cleanup will also happen whenever a new server is successfully added to the cluster.

Expand Down
2 changes: 1 addition & 1 deletion roles/consul/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ consul_env_vars:

### Autopilot
consul_autopilot_enable: "{{ lookup('env', 'CONSUL_AUTOPILOT_ENABLE') | default(false, true) }}"
consul_autopilot_cleanup_dead_Servers: "{{ lookup('env', 'CONSUL_AUTOPILOT_CLEANUP_DEAD_SERVERS') | default(false, true) }}"
consul_autopilot_cleanup_dead_servers: "{{ lookup('env', 'CONSUL_AUTOPILOT_CLEANUP_DEAD_SERVERS') | default(false, true) }}"
consul_autopilot_last_contact_threshold: "{{ lookup('env', 'CONSUL_AUTOPILOT_LAST_CONTACT_THRESHOLD') | default('200ms', true) }}"
consul_autopilot_max_trailing_logs: "{{ lookup('env', 'CONSUL_AUTOPILOT_MAX_TRAILING_LOGS') | default(250, true) }}"
consul_autopilot_server_stabilization_time: "{{ lookup('env', 'CONSUL_AUTOPILOT_SERVER_STABILIZATION_TIME') | default('10s', true) }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/consul/tasks/dnsmasq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
mode: 0644
become: true
notify: restart dnsmasq
when: "{{ dnsmasq_item.when }}"
when: dnsmasq_item.when
tags: dnsmasq
loop:
- { dest: '/etc/dnsmasq.d/10-consul', group: 'root', when: ansible_os_family|lower != "freebsd" }
Expand Down
4 changes: 3 additions & 1 deletion roles/consul/tasks/encrypt_gossip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

- block:
- name: Read gossip encryption key from previously boostrapped server
shell: 'cat {{ consul_config_path }}/bootstrap/config.json | grep "encrypt" | sed -E ''s/"encrypt": "(.+)",?/\1/'' | sed ''s/^ *//;s/ *$//'''
shell: |
set -o pipefail
cat {{ consul_config_path }}/bootstrap/config.json | grep "encrypt" | sed -E 's/"encrypt": "(.+)",?/\1/' | sed 's/^ *//;s/ *$//'
register: consul_key_read
run_once: true

Expand Down
2 changes: 1 addition & 1 deletion roles/consul/templates/config.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
{## AutoPilot ##}
{% if consul_autopilot_enable | bool %}
"autopilot": {
"cleanup_dead_servers": {{ consul_autopilot_cleanup_dead_Servers | bool | to_json }},
"cleanup_dead_servers": {{ consul_autopilot_cleanup_dead_servers | bool | to_json }},
"last_contact_threshold": "{{ consul_autopilot_last_contact_threshold }}",
"max_trailing_logs": {{ consul_autopilot_max_trailing_logs }},
"server_stabilization_time": "{{ consul_autopilot_server_stabilization_time }}"{{ ',' if consul_enterprise else '' }}
Expand Down

0 comments on commit 6f4fe12

Please sign in to comment.