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

Utilize comment filter for ansible_managed annotations #176

Merged

Conversation

growi
Copy link
Contributor

@growi growi commented Mar 13, 2024

What

Changes all template files that include the {{ ansible_managed }} annotation to include {{ ansible_managed | comment }} or, in case of XML templates , {{ ansible_managed | comment('xml') }} instead.
Documentation: Ansible: manipulating-text

Why

The {{ ansible_managed }} vairable is configurable via the ansible.cfg file and can be a multiline string in which case the form # {{ ansible_managed }} used in keycloak.conf.j2, keycloak.service.j2 and keycloak-sysconfig.j2 breaks the file. XML templates that use <!-- {{ ansible_managed }} --> are ok and I only changed them for consistency.

Example

ansible.cfg

ansible_managed = WARNING: This file is managed by ANSIBLE.
  template: {file}
  modified on: %Y-%m-%d %H:%M:%S
  by user: {uid}

# {{ ansible_managed }} renders an invalid unit file:

# WARNING: This file is managed by ANSIBLE.
 template: roles/keycloak/templates/keycloak.service.j2
 modified on: 2024-03-13 00:39:13
 by user: root
[Unit]
Description=Keycloak Server
After=network.target
...

The Service can still be started but no longer enabled. Verify with systemd-analyze
# systemd-analyze verify /etc/systemd/system/keycloak.service

/etc/systemd/system/keycloak.service:2: Assignment outside of section. Ignoring.
/etc/systemd/system/keycloak.service:3: Assignment outside of section. Ignoring.
/etc/systemd/system/keycloak.service:4: Assignment outside of section. Ignoring.

{{ ansible_managed | comment }} renders a valid unit file:

#
# WARNING: This file is managed by ANSIBLE.
# template: roles/keycloak/templates/keycloak.service.j2
# modified on: 2024-03-13 00:39:25
# by user: root
#
[Unit]
Description=Keycloak Server
After=network.target
...

Side Effects

None

Signed-off-by: Björn Großewinkelmann <bgrossew@redhat.com>
@guidograzioli guidograzioli added the bugfixes Fixes that resolve issues. SHOULD not be used for minor enhancements label Mar 13, 2024
Copy link
Member

@guidograzioli guidograzioli left a comment

Choose a reason for hiding this comment

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

PR looks good to me, thanks for the contribution!

@guidograzioli guidograzioli changed the title Utilize comment filter for {{ ansible_maanged }} annotations Utilize comment filter for ansible_managed annotations Mar 13, 2024
@guidograzioli guidograzioli merged commit a875166 into ansible-middleware:main Mar 13, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfixes Fixes that resolve issues. SHOULD not be used for minor enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants