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

fix: Correct conditional checks for PSA config existence and Ansible managed comments #257

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ismoilovdevml
Copy link

@ismoilovdevml ismoilovdevml commented Sep 7, 2024

What type of PR is this?

  • bug

What this PR does / why we need it:

This PR addresses two related issues in the add-pod-security-admission-config.yml task of the RKE2 server role:

  1. Fixing Conditional Check for PSA Config Existence: The previous conditional used is false, which caused an Ansible error. The condition is now correctly evaluated with not and | bool to check the PSA config file's existence.
  2. Fixing Conditional Check for Ansible Managed Comments: The check for Ansible managed comments also used is false incorrectly. This has been corrected using not and | bool to ensure that the file is only removed if it contains Ansible managed comments.

Which issue(s) this PR fixes:

there is no such issue

Special notes for your reviewer:

Please review the changes to ensure that:

  • The PSA config file is properly checked for existence before removal.
  • The check for Ansible managed comments functions as expected.

Testing

Tested locally by running the playbook with and without the PSA config file. Verified that the file is only removed when it exists and contains Ansible managed comments.

Release Notes

Fix conditional checks in RKE2 server role for PSA config file existence and Ansible managed comments to prevent errors during playbook execution.

The following errors were observed

TASK [rke2_server : Check that the PSA config file has ansible managed comments] ************************************************************************************************************************************************************
fatal: [10.128.0.22]: FAILED! => {"msg": "The conditional check 'stat_result.stat.exists | bool is true' failed. The error was: template error while templating string: no test named 'true'. String: {% if stat_result.stat.exists | bool is true %} True {% else %} False {% endif %}\n\nThe error appears to be in '/home/ismoilovdev/rke2-ansible/roles/rke2_server/tasks/add-pod-security-admission-config.yml': line 31, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: \"Check that the PSA config file has ansible managed comments\"\n      ^ here\n"}
fatal: [10.128.0.23]: FAILED! => {"msg": "The conditional check 'stat_result.stat.exists | bool is true' failed. The error was: template error while templating string: no test named 'true'. String: {% if stat_result.stat.exists | bool is true %} True {% else %} False {% endif %}\n\nThe error appears to be in '/home/ismoilovdev/rke2-ansible/roles/rke2_server/tasks/add-pod-security-admission-config.yml': line 31, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: \"Check that the PSA config file has ansible managed comments\"\n      ^ here\n"}
fatal: [10.162.0.2]: FAILED! => {"msg": "The conditional check 'stat_result.stat.exists | bool is true' failed. The error was: template error while templating string: no test named 'true'. String: {% if stat_result.stat.exists | bool is true %} True {% else %} False {% endif %}\n\nThe error appears to be in '/home/ismoilovdev/rke2-ansible/roles/rke2_server/tasks/add-pod-security-admission-config.yml': line 31, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: \"Check that the PSA config file has ansible managed comments\"\n      ^ here\n"}
TASK [rke2_server : Remove the PSA config file if exists and has ansible managed comments] **************************************************************************************************************************************************
fatal: [10.128.0.22]: FAILED! => {"msg": "The conditional check 'ansible_managed_check.changed | bool is false' failed. The error was: template error while templating string: no test named 'false'. String: {% if ansible_managed_check.changed | bool is false %} True {% else %} False {% endif %}\n\nThe error appears to be in '/home/ismoilovdev/rke2-ansible/roles/rke2_server/tasks/add-pod-security-admission-config.yml': line 40, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: Remove the PSA config file if exists and has ansible managed comments\n      ^ here\n"}
fatal: [10.128.0.23]: FAILED! => {"msg": "The conditional check 'ansible_managed_check.changed | bool is false' failed. The error was: template error while templating string: no test named 'false'. String: {% if ansible_managed_check.changed | bool is false %} True {% else %} False {% endif %}\n\nThe error appears to be in '/home/ismoilovdev/rke2-ansible/roles/rke2_server/tasks/add-pod-security-admission-config.yml': line 40, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: Remove the PSA config file if exists and has ansible managed comments\n      ^ here\n"}
fatal: [10.162.0.2]: FAILED! => {"msg": "The conditional check 'ansible_managed_check.changed | bool is false' failed. The error was: template error while templating string: no test named 'false'. String: {% if ansible_managed_check.changed | bool is false %} True {% else %} False {% endif %}\n\nThe error appears to be in '/home/ismoilovdev/rke2-ansible/roles/rke2_server/tasks/add-pod-security-admission-config.yml': line 40, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: Remove the PSA config file if exists and has ansible managed comments\n      ^ here\n"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant