-
Notifications
You must be signed in to change notification settings - Fork 225
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
[debian] Fix role idempotence #262
Conversation
@KSerrania Looping back on this: I can confirm that the role is now idempotent. Thank you! 🚀 |
set_fact: | ||
datadog_remove_custom_repo_file: "{{ datadog_repo_file_contents != datadog_apt_repo }}" | ||
vars: | ||
datadog_repo_file_contents: "{{ lookup('file', '/etc/apt/sources.list.d/ansible_datadog_custom.list') }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting the following error when running this change on my local system against my production inventory:
TASK [Datadog.datadog : Flag custom repository file for deletion if different from current repository config] ************************************************************************************************************************
task path: Datadog.datadog/tasks/pkg-debian.yml:58
[WARNING]: Unable to find '/etc/apt/sources.list.d/ansible_datadog_custom.list' in expected paths (use -vvvvv to see paths)
fatal: [basil-docker.dcenter.delphix.com]: FAILED! => {"msg": "An unhandled exception occurred while templating '{{ lookup('file', '/etc/apt/sources.list.d/ansible_datadog_custom.list') }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while running the lookup plugin 'file'. Error was a <class 'ansible.errors.AnsibleError'>, original message: could not locate file in lookup: /etc/apt/sources.list.d/ansible_datadog_custom.list"}
The /etc/apt/sources.list.d/ansible_datadog_custom.list
file exists on the system in my production inventory, but it does not exist on my local system.
Looking at the documentation for lookup plugins, I see the following:
Like all templating, these plugins are evaluated on the Ansible control machine, not on the target/remote.
Perhaps we should be using the slurp module to read the file from the remote node instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @basil,
Thanks for the report! Indeed, using a lookup plugin doesn't work as we wanted it to do. I'll try using the slurp
module instead and do a bugfix release with this if that works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the fix: #275
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick fix! I just tested this and it works.
What does this PR do?
After the big 4.0 refactor, the debian part of the role was not idempotent anymore (on every run, two tasks would be marked as "changed", even when no changes were made to the config).
This PR fixes that by adding some logic around the custom repository to keep the current behavior while making the role idempotent.
Motivation
Make role idempotent again on Debian.
Additional Notes
Improves upon #250, with help from @jharley.