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

node_exporter role errors out when templating the systemd service #452

Closed
christian-heusel opened this issue Nov 6, 2024 · 9 comments
Closed

Comments

@christian-heusel
Copy link

TASK [prometheus.prometheus._common : Create systemd service unit node_exporter] *****************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'packages'
fatal: [cherry]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'packages'"}

PLAY RECAP ***************************************************************************************************************************************************
cherry                     : ok=17   changed=0    unreachable=0    failed=1    skipped=6    rescued=0    ignored=0   

Since the issue sounds really similar to the issue #342 which I previously opened I also made sure that packages are generally detected when doing a ansible -m ansible.builtin.package_facts cherry but I think the fact collection for packages is not even run at all. Also issue #451 sounds similar given the symptoms but seems to have a entirely different root cause.

Versions:

  • ansible: 10.5.0
  • ansible-core: 2.17.5
  • prometheus-community: 0.22.0
Click to see log of full run
ansible-playbook playbooks/server.yml -l webserver --diff        

PLAY [all] ***************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [cherry]

TASK [ssh-keys : Set authorized key] *************************************************************************************************************************
[...]

TASK [prometheus.prometheus.node_exporter : Validating arguments against arg spec 'main' - Prometheus Node Exporter] *****************************************
ok: [cherry]

TASK [prometheus.prometheus.node_exporter : Preflight] *******************************************************************************************************
included: /home/chris/.ansible/collections/ansible_collections/prometheus/prometheus/roles/node_exporter/tasks/preflight.yml for cherry

TASK [Common preflight] **************************************************************************************************************************************
included: prometheus.prometheus._common for cherry

TASK [prometheus.prometheus._common : Validate invocation of _common role] ***********************************************************************************
ok: [cherry] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [prometheus.prometheus._common : Check for deprecated skip_install variable] ****************************************************************************
ok: [cherry] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [prometheus.prometheus._common : Check for deprecated binary_local_dir variable] ************************************************************************
ok: [cherry] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [prometheus.prometheus._common : Check for deprecated archive_path variable] ****************************************************************************
ok: [cherry] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [prometheus.prometheus._common : Naive assertion of proper listen address] ******************************************************************************
ok: [cherry] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [prometheus.prometheus.node_exporter : Assert that used version supports listen address type] ***********************************************************
ok: [cherry] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [prometheus.prometheus.node_exporter : Assert collectors are not both disabled and enabled at the same time] ********************************************
skipping: [cherry]

TASK [prometheus.prometheus.node_exporter : Assert that TLS key and cert path are set] ***********************************************************************
skipping: [cherry]

TASK [prometheus.prometheus.node_exporter : Check existence of TLS cert file] ********************************************************************************
skipping: [cherry]

TASK [prometheus.prometheus.node_exporter : Check existence of TLS key file] *********************************************************************************
skipping: [cherry]

TASK [prometheus.prometheus.node_exporter : Assert that TLS key and cert are present] ************************************************************************
skipping: [cherry]

TASK [Install] ***********************************************************************************************************************************************
included: prometheus.prometheus._common for cherry

TASK [prometheus.prometheus._common : Validate invocation of _common role] ***********************************************************************************
ok: [cherry] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [prometheus.prometheus._common : Check existence of binary install dir] *********************************************************************************
ok: [cherry]

TASK [SELinux] ***********************************************************************************************************************************************
skipping: [cherry]

TASK [prometheus.prometheus.node_exporter : Configure] *******************************************************************************************************
included: /home/chris/.ansible/collections/ansible_collections/prometheus/prometheus/roles/node_exporter/tasks/configure.yml for cherry

TASK [Configure] *********************************************************************************************************************************************
included: prometheus.prometheus._common for cherry

TASK [prometheus.prometheus._common : Validate invocation of _common role] ***********************************************************************************
ok: [cherry] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [prometheus.prometheus._common : Create systemd service unit node_exporter] *****************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'packages'
fatal: [cherry]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'packages'"}

PLAY RECAP ***************************************************************************************************************************************************
cherry                     : ok=17   changed=0    unreachable=0    failed=1    skipped=6    rescued=0    ignored=0   

@gardar
Copy link
Member

gardar commented Nov 6, 2024

I believe that you are correct in the assumption that the config fails due to the fact that the package facts are missing, but something looks off in that log, there are missing tasks such as Assert usage of systemd as an init system, Install dependencies and finally the Gather package facts one.

What does your playbook and inventory look like? Might be useful to see the output of ansible-config dump --only-changed -t all also.

@christian-heusel
Copy link
Author

christian-heusel commented Nov 6, 2024

I invoke it with ansible-playbook playbooks/server.yml -l webserver --diff and this is what the playbook looks like:

---
- hosts: all
  roles:
    - ssh-keys
    - prometheus.prometheus.node_exporter

This is the output of ansible-config dump --only-changed -t all:

ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
CONFIG_FILE() = /home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg
DEFAULT_FORKS(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = 20
DEFAULT_HOST_LIST(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = ['/home/chris/Documents/shared_projects/ansible-mathphys/hosts.ini']
DEFAULT_ROLES_PATH(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = ['/home/chris/Documents/shared_projects/ansible-mathphys/roles']
EDITOR(env: EDITOR) = nvim
INTERPRETER_PYTHON(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = /usr/bin/python3
PAGER(env: PAGER) = less
RETRY_FILES_ENABLED(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = False
TAGS_SKIP(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = ['install']

GALAXY_SERVERS:


CONNECTION:
==========

ssh:
___
control_path(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = /tmp/ansible-%%h-%%p-%%r
pipelining(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = True
ssh_args(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = -C -o ControlMaster=auto -o ControlPersist=1800s

This is the hosts file:

[nfsserver]
blueberry

[kvmhost]
xerophyte

[webserver]
cherry

[mailserver]
dragonfruit

[backupserver]
spinach

[monitoringserver]
spinach

[teleport]
apple

[clients]
blueberry
arcadia

@gardar
Copy link
Member

gardar commented Nov 6, 2024

TAGS_SKIP(/home/chris/Documents/shared_projects/ansible-mathphys/ansible.cfg) = ['install']

This is the culpit, the package facts step is tagged with install

@christian-heusel
Copy link
Author

Oh my .. Sorry for not spotting this myself! Thanks a ton for the help! ❤️

@gardar
Copy link
Member

gardar commented Nov 6, 2024

No problem, it is however something that we should probably fix since you should be able to run the configure without install.

@christian-heusel
Copy link
Author

Feel free to reopen/re-title this issue as a reminder if you want!

@gardar
Copy link
Member

gardar commented Nov 6, 2024

If you want to PR-it up then I'd be happy to accept it

@christian-heusel
Copy link
Author

If you want to PR-it up then I'd be happy to accept it

I had a quick look, but tbh I'm not sure what needs to be done there as the task already has the configure tag set 😅

- name: Gather package facts
ansible.builtin.package_facts:
when: "not 'packages' in ansible_facts"
tags:
- "{{ ansible_parent_role_names | first | regex_replace(ansible_collection_name ~ '.', '') }}"
- configure
- "{{ ansible_parent_role_names | first | regex_replace(ansible_collection_name ~ '.', '') }}_configure"
- install
- "{{ ansible_parent_role_names | first | regex_replace(ansible_collection_name ~ '.', '') }}_install"

@gardar
Copy link
Member

gardar commented Nov 8, 2024

Yes but the install tag should be removed since the package facts are currently only used by configuration tasks

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

No branches or pull requests

2 participants