Netdata Community

Ansible: Netdata agent deployment - inventory syntax


ansible 2.10.3 on WSL 2 (Ubuntu 20.04.2 LTS)


Possibly a dumb question but I’ve been testing deployment of Netdata using Ansible (as per community/netdata-agent-deployment/ansible-quickstart at main · netdata/community · GitHub) but it seems to fail if I don’t provide IP addresses in the host inventory

(FAILED! => {“changed”: false, “msg”: “AnsibleUndefinedVariable: ‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘hostname’”}).

It seems to pass the “Install Netdata” play without incident but falls over on the “Configure Netdata” play at the “template” task.

“ubuntu01.acme.local” fails
“ubuntu01” fails
“ hostname=ubuntu01” works
“ hostname=ubuntu01.acme.local” works

  1. Is this expected behaviour or am I missing something?*
  2. Can anyone else repro this?
  3. If it is then expected then is there a way to use only FQDN’s (which is what I normally do with Ansible as my DNS infrastructure works well and IP addresses do change)?
  • Yes, I know the document says to include the IP address but it also says to include the “ansible_user” variable, which isn’t necessary if it’s correctly defined elsewhere or matches the existing ansible user. So I’m more curious about why this seems to be a hard requirement rather than an optional parameter.

What I expected to happen

I’d expect that any inventory is handled the same way as any other playbook, letting me specify inventory in whatever way works for me; I’d say being able to use only DNS names should be a minimum requirement (if the control-node can resolve what’s in the hostfile then we should not have any more requirements).
Moreover, requiring IP addresses isn’t very scalable nor even desirable in many circumstances.

Hello my friend welcome back :slight_smile:

I’ve been trying to learn and use ansible a little myself recently so am curious although not sure i’m able to help as a total newb to ansible.

@OdysLam is on vacation at the moment and probably most familiar with that community playbook.

Not sure if @Austin_Hemmelgarn might have some ideas too maybe.

I’m kind of flailing around here but wondering if any examples from the wider community that might have tackled this in some way before:

Hey @Luis_Johnstone, welcome back!

Unfortunately, I am not familiar with Ansible and that particular guide. As it “lives” in our community repo, it’s mostly an example of how Netdata can be super charged with other apps. We don’t really maintain or support the community repo, but instead we offer it as an easy way for community members to showcase their cool projects.

But, this is an interesting question. I will do some lookup and return with any findings.

A regular hostname should work in the inventory file. If it doesn’t then it’s either an issue with Ansible itself, or an issue with the playbook (I’m inclined to believe ti’s the playbook though based on personal experience working with Ansible).

As we saw in Discord, the real issue is the guidance to add the IP, which doesn’t make sense and apparently is only used as an identifier, to get to the hostname. Looks like we need a PR that changes under the following:

  • /templates/netdata.conf.j2 to just use a simple hostname and not an array with attributes
  • /hosts to have an example with just resolvable hostnames
  • / to just request a list of resolvable hostnames

@Luis_Johnstone would you be willing to make the changes? There is a workaround of course, you just provide some dummy value, distinct for each line instead of an IP and it should work.