Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduced consul_systemd_service_name variable #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ consul_systemd_restart: on-failure
consul_systemd_restart_sec: 42
consul_systemd_limit_nofile: 65536
consul_systemd_unit_path: /lib/systemd/system
consul_systemd_service_name: consul

### Log user, group, facility
syslog_user: "{{ lookup('env', 'SYSLOG_USER') | default('root', true) }}"
Expand Down
4 changes: 2 additions & 2 deletions handlers/restart_consul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- name: Restart consul on Unix
ansible.builtin.service:
name: consul
name: "{{ consul_systemd_service_name }}"
state: restarted
# Needed to force SysV service manager on Docker for Molecule tests
use: "{{ ansible_service_mgr }}"
Expand Down Expand Up @@ -38,7 +38,7 @@

- name: Restart consul on Windows
ansible.windows.win_service:
name: consul
name: "{{ consul_systemd_service_name }}"
state: restarted
# Some tasks with `become: true` end up calling this task. Unfortunately, the `become`
# property is evaluated before the `when` condition and this results in an Ansible
Expand Down
4 changes: 2 additions & 2 deletions handlers/start_consul.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Start consul on Unix
ansible.builtin.service:
name: consul
name: "{{ consul_systemd_service_name }}"
state: started
# Needed to force SysV service manager on Docker for Molecule tests
use: "{{ ansible_service_mgr }}"
Expand All @@ -17,7 +17,7 @@

- name: Start consul on Windows
ansible.windows.win_service:
name: consul
name: "{{ consul_systemd_service_name }}"
state: started
when: ansible_os_family == "Windows"
listen: start consul
8 changes: 4 additions & 4 deletions tasks/install_linux_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

- name: Stop service consul, if running
ansible.builtin.service:
name: consul
name: "{{ consul_systemd_service_name }}"
state: stopped
# Needed to force SysV service manager on Docker for Molecule tests
use: "{{ ansible_service_mgr }}"
Expand Down Expand Up @@ -80,9 +80,9 @@
state: present
become: true

- name: Create a directory /etc/systemd/system/consul.service.d
- name: "Create a directory /etc/systemd/system/{{ consul_systemd_service_name }}.service.d"

Check failure on line 83 in tasks/install_linux_repo.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

name[template]

Jinja templates should only be at the end of 'name'
ansible.builtin.file:
path: /etc/systemd/system/consul.service.d
path: "/etc/systemd/system/{{ consul_systemd_service_name }}.service.d"
state: directory
mode: "0755"
owner: root
Expand All @@ -94,7 +94,7 @@
- name: Override systemd service params
ansible.builtin.template:
src: consul_systemd_service.override.j2
dest: /etc/systemd/system/consul.service.d/override.conf
dest: "/etc/systemd/system/{{ consul_systemd_service_name }}.service.d/override.conf"
Copy link
Contributor

@nre-ableton nre-ableton Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes an ansible-lint violation, since templating Ansible task names only works if the template is at the very end of the string. You'll need to reword the task (and drop the quotes) to make this work.

owner: root
group: root
mode: "0644"
Expand Down
2 changes: 1 addition & 1 deletion tasks/leave_restart_consul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- name: Restart consul on Unix
delegate_to: "{{ rolling_restart_host }}"
ansible.builtin.service:
name: consul
name: "{{ consul_systemd_service_name }}"
state: restarted
# Needed to force SysV service manager on Docker for Molecule tests
use: "{{ ansible_service_mgr }}"
Expand Down
6 changes: 3 additions & 3 deletions tasks/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
- name: Create systemd script
ansible.builtin.template:
src: consul_systemd.service.j2
dest: "{{ consul_systemd_unit_path }}/consul.service"
dest: "{{ consul_systemd_unit_path }}/{{ consul_systemd_service_name }}.service"
owner: root
group: root
mode: "0644"
Expand All @@ -254,7 +254,7 @@

- name: Enable consul at startup (systemd)
ansible.builtin.systemd_service:
name: consul
name: "{{ consul_systemd_service_name }}"
enabled: true
when:
- ansible_service_mgr == "systemd"
Expand Down Expand Up @@ -312,7 +312,7 @@
block:
- name: Start Consul
ansible.builtin.service:
name: consul
name: "{{ consul_systemd_service_name }}"
state: started
enabled: true
# Needed to force SysV service manager on Docker for Molecule tests
Expand Down
4 changes: 2 additions & 2 deletions templates/consul_systemd_snapshot.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[Unit]
Description=Consul snapshot agent
Requires=network-online.target
Requisite=consul.service
Requisite={{ consul_systemd_service_name }}.service
After=network-online.target

[Service]
Expand All @@ -30,4 +30,4 @@ Environment={{ var }}
{% endfor %}

[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
Loading