Skip to content

Commit 4f2f6c8

Browse files
authored
Release 1.0.3 - Refactor Tailscale systemd override architecture (#28)
* Release 1.0.3 - Refactor Tailscale systemd override architecture Refactor Tailscale role systemd service override handling for better maintainability and correct systemd directive placement. Consolidate two separate override templates into one, move configuration defaults to Ansible variables, and fix Unit vs Service section handling. Key changes: - Consolidated config-override.conf.j2 and override.conf.j2 templates - Moved ExecStart override to tailscale_service_override in defaults - Fixed systemd directive section placement (Unit vs Service) - Added cleanup task for legacy config-override.conf - Updated argument_specs.yml with detailed documentation - Improved code readability with YAML multiline formatting * Fix line length in argument_specs.yml Break long ExecStart line into multiple lines to comply with yamllint line-length rule (max 160 characters).
1 parent 98a1540 commit 4f2f6c8

File tree

8 files changed

+102
-47
lines changed

8 files changed

+102
-47
lines changed

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ All notable changes to this project will be documented in this file.
77

88
## [Unreleased]
99

10+
## [1.0.3] - 2026-02-02
11+
12+
### Changed
13+
14+
- **Tailscale Role** - Refactored systemd service override architecture
15+
- Consolidated `config-override.conf.j2` and `override.conf.j2` into single unified template
16+
- Moved ExecStart override logic from template to [defaults/main.yml](roles/tailscale/defaults/main.yml:19-27)
17+
- Fixed Unit vs Service section directive handling in systemd overrides
18+
- Added automatic cleanup task for legacy `config-override.conf` file
19+
- Updated [argument_specs.yml](roles/tailscale/meta/argument_specs.yml:47-68) with detailed documentation and examples
20+
- Improved YAML formatting with multiline syntax for better readability
21+
22+
### Fixed
23+
24+
- **Tailscale Role** - Fixed systemd directive placement errors
25+
- Unit directives (After, Wants, PartOf, ReloadPropagatedFrom) now correctly placed in `[Unit]` section
26+
- Service directives (ExecStart, Environment, etc.) correctly placed in `[Service]` section
27+
- Resolves systemd warning: "Unknown key name in section 'Service'"
28+
1029
## [1.0.2] - 2026-02-02
1130

1231
### Fixed
@@ -281,7 +300,8 @@ For detailed configuration examples, see the [Alloy role README](roles/alloy/REA
281300

282301
See: <https://github.com/arillso/ansible.agent/releases>
283302

284-
[Unreleased]: https://github.com/arillso/ansible.agent/compare/1.0.2...HEAD
303+
[Unreleased]: https://github.com/arillso/ansible.agent/compare/1.0.3...HEAD
304+
[1.0.3]: https://github.com/arillso/ansible.agent/compare/1.0.2...1.0.3
285305
[1.0.2]: https://github.com/arillso/ansible.agent/compare/1.0.1...1.0.2
286306
[1.0.1]: https://github.com/arillso/ansible.agent/compare/1.0.0...1.0.1
287307
[1.0.0]: https://github.com/arillso/ansible.agent/releases/tag/1.0.0

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace: arillso
99
name: agent
1010

1111
# The version of the collection. Must be compatible with semantic versioning
12-
version: 1.0.2
12+
version: 1.0.3
1313

1414
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1515
readme: README.md

roles/tailscale/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ Installs and configures Tailscale VPN for secure mesh networking with support fo
1616

1717
For detailed documentation including all variables, examples, and usage instructions, see:
1818

19-
**<https://guide.arillso.io/collections/arillso/agent/tailscale_role.html>**
19+
**[Complete Documentation][docs]**
20+
21+
[docs]: https://guide.arillso.io/collections/arillso/agent/tailscale_role.html?utm_source=github&utm_medium=readme&utm_campaign=documentation&utm_content=tailscale_role
2022

2123
## Quick Start
2224

roles/tailscale/defaults/main.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ tailscale_tags: []
1616
tailscale_reset_authentication: false
1717

1818
tailscale_preferences: {}
19-
tailscale_service_override: {}
19+
tailscale_service_override:
20+
ExecStart:
21+
- ""
22+
- >-
23+
/usr/sbin/tailscaled
24+
--state=/var/lib/tailscale/tailscaled.state
25+
--socket=/run/tailscale/tailscaled.sock
26+
--port=${PORT}
27+
--config={{ tailscale_config_file }}
2028
2129
tailscale_server_url: ""
2230
tailscale_locked: ""

roles/tailscale/meta/argument_specs.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,26 @@ argument_specs:
4747
tailscale_service_override:
4848
type: "dict"
4949
required: false
50-
default: {}
51-
description: "Dictionary of systemd service override parameters"
50+
default:
51+
ExecStart:
52+
- ""
53+
- >-
54+
/usr/sbin/tailscaled --state=/var/lib/tailscale/tailscaled.state
55+
--socket=/run/tailscale/tailscaled.sock --port=${PORT}
56+
--config=/etc/tailscale/config.json
57+
description: |
58+
Dictionary of systemd service override parameters for tailscaled.service.
59+
Default includes ExecStart override to enable daemon config file support.
60+
61+
Supports both Unit and Service section directives:
62+
- Unit directives: After, Before, Wants, Requires, PartOf, Conflicts, etc.
63+
- Service directives: ExecStart, ExecStartPre, Environment, etc.
64+
65+
Examples:
66+
- Override ExecStart: tailscale_service_override: {ExecStart: ["", "/custom/path"]}
67+
- Add environment: tailscale_service_override: {Environment: {VAR: "value"}}
68+
- Add dependencies: tailscale_service_override: {After: ["network.target"]}
69+
- Disable config: tailscale_service_override: {} (empty dict)
5270
5371
# Authentication
5472
tailscale_auth_key:

roles/tailscale/tasks/configure.yml

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,30 @@
5656
notify: reload tailscale config
5757
tags: [tailscale, config, daemon]
5858

59-
- name: Configure systemd service to use daemon config file
59+
- name: Create Tailscale systemd override directory
60+
ansible.builtin.file:
61+
path: /etc/systemd/system/tailscaled.service.d
62+
state: directory
63+
mode: "0755"
64+
owner: root
65+
group: root
66+
become: true
67+
when: >
68+
(tailscale_config_enabled | default(true) | bool and _tailscale_has_config | bool) or
69+
(tailscale_service_override | length > 0)
70+
tags: [tailscale, config, systemd]
71+
72+
- name: Configure Tailscale systemd service override
6073
ansible.builtin.template:
61-
src: etc/systemd/system/tailscaled.service.d/config-override.conf.j2
62-
dest: /etc/systemd/system/tailscaled.service.d/config-override.conf
74+
src: etc/systemd/system/tailscaled.service.d/override.conf.j2
75+
dest: /etc/systemd/system/tailscaled.service.d/override.conf
6376
mode: "0644"
6477
owner: root
6578
group: root
6679
become: true
67-
when:
68-
- tailscale_config_enabled | default(true) | bool
69-
- _tailscale_has_config | bool
80+
when: >
81+
(tailscale_config_enabled | default(true) | bool and _tailscale_has_config | bool) or
82+
(tailscale_service_override | length > 0)
7083
notify:
7184
- reload systemd
7285
- restart tailscaled
@@ -86,31 +99,6 @@
8699
no_log: "{{ tailscale_no_log_auth_key | default(true) }}"
87100
tags: [tailscale, config, auth]
88101

89-
- name: Create Tailscale systemd override directory
90-
ansible.builtin.file:
91-
path: /etc/systemd/system/tailscaled.service.d
92-
state: directory
93-
mode: "0755"
94-
owner: root
95-
group: root
96-
become: true
97-
when: tailscale_service_override | length > 0
98-
tags: [tailscale, config, systemd]
99-
100-
- name: Configure Tailscale systemd service override
101-
ansible.builtin.template:
102-
src: etc/systemd/system/tailscaled.service.d/override.conf.j2
103-
dest: /etc/systemd/system/tailscaled.service.d/override.conf
104-
mode: "0644"
105-
owner: root
106-
group: root
107-
become: true
108-
when: tailscale_service_override | length > 0
109-
notify:
110-
- reload systemd
111-
- restart tailscaled
112-
tags: [tailscale, config, systemd]
113-
114102
# Reset authentication if requested
115103
- name: Reset Tailscale configuration (logout and re-authenticate)
116104
when: tailscale_reset_authentication | default(false) | bool

roles/tailscale/templates/etc/systemd/system/tailscaled.service.d/config-override.conf.j2

Lines changed: 0 additions & 8 deletions
This file was deleted.

roles/tailscale/templates/etc/systemd/system/tailscaled.service.d/override.conf.j2

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
# Tailscale Systemd Service Override Template
2-
# Template for systemd service override configuration
2+
# Consolidated override configuration for daemon config and custom settings
3+
# Reference: https://tailscale.com/kb/1654/tailscaled-config-file
4+
{% set unit_directives = ['After', 'Before', 'Wants', 'Requires', 'PartOf', 'Conflicts', 'ReloadPropagatedFrom', 'BindsTo', 'Requisite', 'OnFailure', 'PropagatesReloadTo', 'JoinsNamespaceOf'] %}
5+
{% set unit_settings = {} %}
6+
{% set service_settings = {} %}
7+
{% for key, value in tailscale_service_override.items() %}
8+
{% if key in unit_directives %}
9+
{% set _ = unit_settings.update({key: value}) %}
10+
{% else %}
11+
{% set _ = service_settings.update({key: value}) %}
12+
{% endif %}
13+
{% endfor %}
14+
15+
{% if unit_settings %}
16+
[Unit]
17+
{% for section, settings in unit_settings.items() %}
18+
{% if settings is iterable and settings is not string %}
19+
# {{ section }} list values
20+
{% for item in settings %}
21+
{{ section }}={{ item }}
22+
{% endfor %}
23+
{% else %}
24+
{{ section }}={{ settings }}
25+
{% endif %}
26+
{% endfor %}
327

28+
{% endif %}
429
[Service]
5-
{% for section, settings in tailscale_service_override.items() %}
30+
{% if service_settings %}
31+
{% for section, settings in service_settings.items() %}
632
{% if section == 'Environment' and settings is mapping %}
733
# Environment variables
834
{% for key, value in settings.items() %}
@@ -44,3 +70,4 @@ ExecStartPre={{ command }}
4470
{{ section }}={{ settings }}
4571
{% endif %}
4672
{% endfor %}
73+
{% endif %}

0 commit comments

Comments
 (0)