From daafa60ff8e8ae40ceee650d6cef8b9fa338970c Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Thu, 18 Sep 2025 14:45:46 +0200 Subject: [PATCH] fix: add set-environment and unset-environment in executable_options for systemctl Fixes: #4784 Signed-off-by: Daniel Ziegenberg --- .../playbooks/rule-command-instead-of-module-pass.yml | 8 ++++++++ src/ansiblelint/rules/command_instead_of_module.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/examples/playbooks/rule-command-instead-of-module-pass.yml b/examples/playbooks/rule-command-instead-of-module-pass.yml index ef08ce3412..535117433a 100644 --- a/examples/playbooks/rule-command-instead-of-module-pass.yml +++ b/examples/playbooks/rule-command-instead-of-module-pass.yml @@ -26,6 +26,14 @@ ansible.builtin.command: systemctl show-environment changed_when: false + - name: Set systemd environment + ansible.builtin.command: systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" + changed_when: false + + - name: Unset systemd environment + ansible.builtin.command: systemctl unset-environment MYSQLD_OPTS + changed_when: false + - name: Get systemd runlevel ansible.builtin.command: systemctl get-default changed_when: false diff --git a/src/ansiblelint/rules/command_instead_of_module.py b/src/ansiblelint/rules/command_instead_of_module.py index af6cda3c05..e7e9378c33 100644 --- a/src/ansiblelint/rules/command_instead_of_module.py +++ b/src/ansiblelint/rules/command_instead_of_module.py @@ -76,6 +76,8 @@ class CommandsInsteadOfModulesRule(AnsibleLintRule): "kill", "set-default", "set-property", + "set-environment", + "unset-environment", "show-environment", "status", "reset-failed",