ansible-datadog
ansible-datadog copied to clipboard
include datadog_skip_install
fixes #430
- Include a default datadog_skip_install variable set to false/no as default
- Don't override datadog_skip install in set-parse-version.yml but check if its set or use default false
Hi 👋 thanks for sending the PR! While I do agree with the idea of making this configurable, I think that if user provides an explicit value, it should override all further assignments to the variable.
I think the way this should work is that we assign e.g. an empty string to the variable in defaults/main.yml. Then in the tasks/set-parse-version.yml file:
- If the value is empty string, do all the assignments that we do now.
- If the value is not empty string, take it and skip all the assignments that we do now.
Does this make sense?
You mean if the user passes the variable with extra_var/cli? This takes already precedence over the variable in inventory (https://docs.ansible.com/ansible/latest/reference_appendices/general_precedence.html).
That said, you are right that currently something is not working. I today learned, that set_fact for variables is not "called" as whole if the variable is passed with extra_vars. This creates problems on boolean variables in newer Ansible versions as cli extra_vars are string type. I always thought one could then call |bool in set_fact but this doesn't work as said.
So there could be two solutions:
- set the variable
datadog_skip_installbut then actually create a_datadog_skip_installconverted one for example inset-parse-version.yml... - ... or just use
datadog_skip_install|boolinstead if the variable is used.
As the datadog_skip_install isn't used that often I would go with variant 2.
Beside the declaration of datadog_skip_install in defaults/main.yml has the nice side effect that one less task call is needed as set_fact in set-parse-version.yml is actually not needed anymore.
Done...
Without the variable set in inventory or cli, the agent will be installed:
datadog-agent on main [✘!?] took 7s
❯ ansible-playbook site.yml -i inventories/hosts.yml --limit host01p
PLAY [linux] ***************************************************************************************************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [set_fact] ************************************************************************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [include_role : datadog.datadog] **************************************************************************************************************************************************************************************************************************************************************************************
TASK [datadog.datadog : Include Gather Ansible Facts task on Ansible >= 2.10] **********************************************************************************************************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/facts-ansible10.yml for host01p
TASK [datadog.datadog : Gather Ansible Facts] ******************************************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [datadog.datadog : Include Gather Ansible Facts task on Ansible < 2.10] ***********************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Check if OS is supported] **************************************************************************************************************************************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/os-check.yml for host01p
TASK [datadog.datadog : Fail if OS is not supported] ***********************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Resolve datadog_tracked_checks later to defend against variable presidence issues arising from dynamically included null datadog_checks] ***********************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/sanitize-checks.yml for host01p
TASK [datadog.datadog : Defend against defined but null datadog_checks variable] *******************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [datadog.datadog : Resolve datadog_tracked_checks] ********************************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [datadog.datadog : Check that datadog_checks is a mapping] ************************************************************************************************************************************************************************************************************************************************************
ok: [host01p] => {
"changed": false,
"msg": "All assertions passed"
}
TASK [datadog.datadog : Set Facts for Datadog Agent Major Version] *********************************************************************************************************************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/set-parse-version.yml for host01p
TASK [datadog.datadog : Convert datadog_agent_major_version to string] *****************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [datadog.datadog : include_tasks] *************************************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Set Agent default major version] *******************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Debian Install Tasks] ******************************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : RedHat Install Tasks] ******************************************************************************************************************************************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/pkg-redhat.yml for host01p
...
PLAY RECAP *****************************************************************************************************************************************************************************************************************************************************************************************************************
host01p : ok=12 changed=0 unreachable=0 failed=0 skipped=5 rescued=0 ignored=0
with overriding the variable in cli the install step will be skipped:
datadog-agent on main [✘!?] took 7s
❯ ansible-playbook site.yml -i inventories/hosts.yml --limit host01p -e datadog_skip_install=yes
PLAY [linux] ***************************************************************************************************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [set_fact] ************************************************************************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [include_role : datadog.datadog] **************************************************************************************************************************************************************************************************************************************************************************************
TASK [datadog.datadog : Include Gather Ansible Facts task on Ansible >= 2.10] **********************************************************************************************************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/facts-ansible10.yml for host01p
TASK [datadog.datadog : Gather Ansible Facts] ******************************************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [datadog.datadog : Include Gather Ansible Facts task on Ansible < 2.10] ***********************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Check if OS is supported] **************************************************************************************************************************************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/os-check.yml for host01p
TASK [datadog.datadog : Fail if OS is not supported] ***********************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Resolve datadog_tracked_checks later to defend against variable presidence issues arising from dynamically included null datadog_checks] ***********************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/sanitize-checks.yml for host01p
TASK [datadog.datadog : Defend against defined but null datadog_checks variable] *******************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [datadog.datadog : Resolve datadog_tracked_checks] ********************************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [datadog.datadog : Check that datadog_checks is a mapping] ************************************************************************************************************************************************************************************************************************************************************
ok: [host01p] => {
"changed": false,
"msg": "All assertions passed"
}
TASK [datadog.datadog : Set Facts for Datadog Agent Major Version] *********************************************************************************************************************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/set-parse-version.yml for host01p
TASK [datadog.datadog : Convert datadog_agent_major_version to string] *****************************************************************************************************************************************************************************************************************************************************
ok: [host01p]
TASK [datadog.datadog : include_tasks] *************************************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Set Agent default major version] *******************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Debian Install Tasks] ******************************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : RedHat Install Tasks] ******************************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Suse Install Tasks] ********************************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Windows Install Tasks] *****************************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Linux Configuration Tasks (Agent 5)] ***************************************************************************************************************************************************************************************************************************************************************
skipping: [host01p]
TASK [datadog.datadog : Linux Configuration Tasks] *************************************************************************************************************************************************************************************************************************************************************************
included: /mnt/c/Users/fism/code/work/datadog-agent/roles/datadog.datadog/tasks/agent-linux.yml for host01p
...
I've tested this agains RHEL Linux. Can someone test this with windows?
Hi 👋
What I meant in my previous comment is that if datadog_skip_install is provided explicitly by the user, we should skip all the other tasks that possibly set it - see https://github.com/DataDog/ansible-datadog/blob/main/tasks/parse-version.yml#L85-L93. I think the best way to do it is to set it to e.g. empty string in the defaults/main.yml file. Then in tasks/parse-version.yml:
- If
datadog_skip_installis empty string, we know that the user didn't provide explicit true/false, hence we let the tasks currently living in thetasks/parse-version.ymlfile do what they do now. - If
datadog_skip_installis not an empty string, we know that the user provided an explicit value. So we should take that value and not modifydatadog_skip_installby further tasks in thetasks/parse-version.ymlfile.
In terms of the |bool conversion, I'd much prefer doing this in one place - the tasks/parse-version.yml file - to centralize how we create that variable and just be sure we have a boolean everywhere else.
I think I see what you mean. I had a rough week and going into easter vacation, but will look into it next week.
Any updates with this PR? We are looking for this exact implementation to be available for our use case. We are creating VM image with a specific agent version and holding it While the checks and configuration bit is done when the VM is provisioned and doesn't need to install datadog agent.