Score:0

Getting error AnsibleUndefinedVariable: 'facter_ipaddress_eth1' when running ansible playbook

br flag

Getting one big error stacktrace of ansible variable not found exception

ansible.errors.AnsibleUndefinedVariable: 'facter_ipaddress_eth1'

while I am runing ansible play book.

the value that gets set here and other places.

https://github.com/vfarcic/docker-swarm-networking/blob/master/ansible/group_vars/all

TASK [docker : Debian files are present] ********************************************************************************************************************************************************task path: /vagrant/ansible/roles/docker/tasks/main.yml:76
<10.100.192.200> ESTABLISH SSH CONNECTION FOR USER: vagrant
<10.100.192.200> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/vagrant/.vagrant/machines/swarm-master/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="vagrant"' -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ceb9f96da5 10.100.192.200 '/bin/sh -c '"'"'echo ~vagrant && sleep 0'"'"''
<10.100.192.200> (0, b'/home/vagrant\n', b'')
<10.100.192.200> ESTABLISH SSH CONNECTION FOR USER: vagrant
<10.100.192.200> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/vagrant/.vagrant/machines/swarm-master/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="vagrant"' -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ceb9f96da5 10.100.192.200 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /home/vagrant/.ansible/tmp `"&& mkdir "` echo /home/vagrant/.ansible/tmp/ansible-tmp-1640389849.3916476-93636-106822855105481 `" && echo ansible-tmp-1640389849.3916476-93636-106822855105481="` echo /home/vagrant/.ansible/tmp/ansible-tmp-1640389849.3916476-93636-106822855105481 `" ) && sleep 0'"'"''
<10.100.192.200> (0, b'ansible-tmp-1640389849.3916476-93636-106822855105481=/home/vagrant/.ansible/tmp/ansible-tmp-1640389849.3916476-93636-106822855105481\n', b'')
<10.100.192.200> ESTABLISH SSH CONNECTION FOR USER: vagrant
<10.100.192.200> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/vagrant/.vagrant/machines/swarm-master/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="vagrant"' -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ceb9f96da5 10.100.192.200 '/bin/sh -c '"'"'rm -f -r /home/vagrant/.ansible/tmp/ansible-tmp-1640389849.3916476-93636-106822855105481/ > /dev/null 2>&1 && sleep 0'"'"''
<10.100.192.200> (0, b'', b'')
The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ansible/template/__init__.py", line 1139, in do_template
    res = j2_concat(rf)
  File "<template>", line 11, in root
  File "/usr/lib/python3/dist-packages/jinja2/runtime.py", line 639, in _fail_with_undefined_error
    raise self._undefined_exception(hint)
jinja2.exceptions.UndefinedError: 'facter_ipaddress_eth1' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ansible/template/vars.py", line 98, in __getitem__
    value = self._templar.template(variable)
  File "/usr/lib/python3/dist-packages/ansible/template/__init__.py", line 869, in template
    result = self.do_template(
  File "/usr/lib/python3/dist-packages/ansible/template/__init__.py", line 1176, in do_template
    raise AnsibleUndefinedVariable(e)
ansible.errors.AnsibleUndefinedVariable: 'facter_ipaddress_eth1' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ansible/template/__init__.py", line 1139, in do_template
    res = j2_concat(rf)
  File "<template>", line 9, in root
  File "/usr/lib/python3/dist-packages/ansible/template/__init__.py", line 404, in resolve_or_missing
    val = super(AnsibleContext, self).resolve_or_missing(key)
  File "/usr/lib/python3/dist-packages/jinja2/runtime.py", line 217, in resolve_or_missing
    return resolve_or_missing(self, key)
  File "/usr/lib/python3/dist-packages/jinja2/runtime.py", line 129, in resolve_or_missing
    return context.parent[key]
  File "/usr/lib/python3/dist-packages/ansible/template/vars.py", line 100, in __getitem__
    raise AnsibleUndefinedVariable("%s: %s" % (to_native(variable), e.message))
ansible.errors.AnsibleUndefinedVariable: {{ facter_ipaddress_eth1 }}: 'facter_ipaddress_eth1' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ansible/plugins/action/template.py", line 150, in run
    resultant = templar.do_template(template_data, preserve_trailing_newlines=True, escape_backslashes=False)
  File "/usr/lib/python3/dist-packages/ansible/template/__init__.py", line 1176, in do_template
    raise AnsibleUndefinedVariable(e)
ansible.errors.AnsibleUndefinedVariable: {{ facter_ipaddress_eth1 }}: 'facter_ipaddress_eth1' is undefined
fatal: [10.100.192.200]: FAILED! => {
    "changed": false,
    "msg": "AnsibleUndefinedVariable: {{ facter_ipaddress_eth1 }}: 'facter_ipaddress_eth1' is undefined"
}

PLAY RECAP **************************************************************************************************************************************************************************************10.100.192.200             : ok=14   changed=6    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

After following @alexD 's advice I have added task to install facter, but I am still getting the same error:

- name: Install facter
  raw: apt install -y facter
  become: true
  tags: [docker]

- name: Check facter
  command: "facter ipaddress_eth1"
  register: result
  tags: [docker]
Score:0
jp flag

To get facter_ variables you need to have facter program installed on the target host. See notes for setup module.

Ciasto piekarz avatar
br flag
well, facter is installed on the host, `facter ipaddress` `2021-12-25 11:12:12.071715 WARN puppetlabs.facter - could not locate a ruby library: facts requiring Ruby will not be resolved. ` `10.0.2.15`
Ciasto piekarz avatar
br flag
you can see I get IP address returned.
djdomi avatar
za flag
but i think you have missing ruby libraries?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.