{"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'"}

7,660 views
Skip to first unread message

Tom K.

unread,
Nov 3, 2018, 4:18:12 PM11/3/18
to Ansible Project
Hey All,

Receiving the following from Ansible 2.7 and not sure if I should be 
predefining a variable and pointing to this fact first or perhaps this 
is related to something else?  (Relatively new to Ansible)

fatal: [mysql04]: FAILED! => {"changed": false, "msg": 
"AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' 
has no attribute 'ansible_default_ipv4'"}



[root@awx01 ansible]# ansible --version
ansible 2.7.0
   config file = /etc/ansible/ansible.cfg
   configured module search path = [u'/root/.ansible/plugins/modules', 
u'/usr/share/ansible/plugins/modules']
   ansible python module location = /usr/lib/python2.7/site-packages/ansible
   executable location = /bin/ansible
   python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 
20150623 (Red Hat 4.8.5-16)]
[root@awx01 ansible]#



[root@awx02 mysql]# cat templates/my.cnf.j2
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
binlog_format=ROW
bind-address="{{ ansible_default_ipv4.address }}"
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=122M
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
wsrep_cluster_name="galera_cluster1"
wsrep_cluster_address="gcomm://{% for host in 
groups['mysql']%}{{hostvars[host]['ansible_default_ipv4']['address']}}{% 
if not loop.last %},{% endif %}{% endfor %}"
wsrep_sst_method=rsync
server_id=1
wsrep_node_address="{{ ansible_default_ipv4.address }}"
wsrep_node_name="{{ ansible_hostname }}"
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@awx02 mysql]#


The fact exists and is defined on the target:


[root@awx01 ansible]# ansible mysql04  -m setup | grep -Ei 192.168.0.109 
-A 2 -B 2
     "ansible_facts": {
         "ansible_all_ipv4_addresses": [
             "192.168.0.109"
         ],
         "ansible_all_ipv6_addresses": [
--
         },
         "ansible_default_ipv4": {
             "address": "192.168.0.109",
             "alias": "eth0",
             "broadcast": "192.168.0.255",
--
             "SHLVL": "2",
             "SSH_CLIENT": "192.168.0.142 49456 22",
             "SSH_CONNECTION": "192.168.0.142 49456 192.168.0.109 22",
             "SSH_TTY": "/dev/pts/1",
             "TERM": "xterm",
--
             "hw_timestamp_filters": [],
             "ipv4": {
                 "address": "192.168.0.109",
                 "broadcast": "192.168.0.255",
                 "netmask": "255.255.255.0",
--
                 "inode_used": 621,
                 "mount": "/n/mds.xyz",
                 "options": 
"rw,relatime,vers=4.1,rsize=8192,wsize=8192,namlen=255,hard,proto=tcp,port=0,timeo=10,retrans=2,sec=sys,clientaddr=192.168.0.10 
,local_lock=none,addr=192.168.0.80",
                 "size_available": 137319276544,
                 "size_total": 137371844608,
[root@awx01 ansible]#


-- Cheers, TK.

Uwe Sauter

unread,
Nov 3, 2018, 4:23:04 PM11/3/18
to ansible...@googlegroups.com
Could you show us the play where this happens?


Am 03.11.18 um 21:18 schrieb Tom K.:
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/bcff4644-fba3-4efe-9434-4b20465d1cd0%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/bcff4644-fba3-4efe-9434-4b20465d1cd0%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Tom K.

unread,
Nov 3, 2018, 7:45:44 PM11/3/18
to Ansible Project
Thanks Uwe!

# cat main.yml
---

- name: Gather all facts prior to execution
  hosts
: mysql
  gather_facts
: yes


- name: Install and configure MySQL
  hosts
: mysql
  sudo
: yes
  roles
:
   
- mysql
  tags
: mysql


The above calls this role:

# vi tasks/main.yml
# These tasks install the community MySQL Server.


- include_tasks: variables.yml

# Place the my.cnf file on the target hosts.
- name: Copy my.cnf global MySQL configuration.
 
template:
    src
: my.cnf.j2
    dest
: "{{ mysql_config_file }}"
    owner
: root
   
group: root
    mode
: 0644
    tags
: mysql



There's a variables.yml file as well but that just defines mysql_config_file .  Let me know if you need to see it.

Cheers,
TK

Vladimir Botka

unread,
Nov 4, 2018, 1:35:14 AM11/4/18
to Ansible Project
"HostVarsVars" looks suspicious in the error message. Where does it come from? Find it and check if this is what you want.

'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'

HTH,

-vlado

Uwe Sauter

unread,
Nov 4, 2018, 2:45:06 AM11/4/18
to ansible...@googlegroups.com
Hi,

Am 04.11.18 um 00:45 schrieb Tom K.:
> Thanks Uwe!
>
> |
> # cat main.yml
> ---
>
> -name:Gatherall facts prior to execution
>   hosts:mysql
>   gather_facts:yes
>
>
> -name:Installandconfigure MySQL
>   hosts:mysql
>   sudo:yes
>   roles:
> -mysql
>   tags:mysql
>
> |


First of all: you don't need the first play gathering facts if you don't suppress it in the second.
"gather_facts: true" is default and thus will be executed in every play (something might have changed
due to actions in the last play…)

> The above calls this role:
>
> |
> # vi tasks/main.yml
> # These tasks install the community MySQL Server.
>
>
> -include_tasks:variables.yml
>
> # Place the my.cnf file on the target hosts.
> -name:Copymy.cnf globalMySQLconfiguration.
> template:
>     src:my.cnf.j2
>     dest:"{{ mysql_config_file }}"
>     owner:root
> group:root
>     mode:0644
>     tags:mysql
>

This looks normal.

In situations like these where I'm unsure at which level of nesting a value can be found I use the following neet trick
to get a glimpse of the variable structure:


- name: my_play
hosts: my_group
gather_facts: false (to speed up execution. Set to true or omit this line if settings have changed in the last play)
tasks:
- (list of preparing tasks, e.g. set_fact)
### debug ####
- name: dump variable output
copy:
dest: /tmp/<variable_name.yaml>
content: '{{ variable_name | to_nice_yaml }}'
- pause: (or fail:)
### end debug ###
- (rest of the play)

With this you'll be able to analyze the structure and see if the attribute / key is actually set for which your playbook
or template is looking.


Regards,

Uwe


>
>
> There's a variables.yml file as well but that just defines mysql_config_file .  Let me know if you need to see it.
>
> Cheers,
> TK
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a1246cf1-4828-477b-aa38-5c8109c334a5%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/a1246cf1-4828-477b-aa38-5c8109c334a5%40googlegroups.com?utm_medium=email&utm_source=footer>.

Tom K.

unread,
Nov 4, 2018, 9:22:22 AM11/4/18
to Ansible Project


On Sunday, November 4, 2018 at 2:45:06 AM UTC-5, Uwe Sauter wrote:
Hi,

Am 04.11.18 um 00:45 schrieb Tom K.:
> Thanks Uwe!
>
> |
> # cat main.yml
> ---
>
> -name:Gatherall facts prior to execution
>    hosts:mysql
>    gather_facts:yes
>
>
> -name:Installandconfigure MySQL
>    hosts:mysql
>    sudo:yes
>    roles:
> -mysql
>    tags:mysql
>
> |


First of all: you don't need the first play gathering facts if you don't suppress it in the second.
"gather_facts: true" is default and thus will be executed in every play (something might have changed
due to actions in the last play…)

I did not have this originally.  It was suggested to try it in one of the posts I was reading so I tacked it on but it made no difference.  
So I've modified the first main.yml as follows:

# cat main.yml
---


- name: Gather all facts prior to execution
  hosts
: mysql
  gather_facts
: false
  tasks
:
   
- name: Dump ansible_default_ipv4 variable output
      copy
:
        dest
: /tmp/ansible_default_ipv4.yaml
        content
: '{{ ansible_default_ipv4 | to_nice_yaml }}'
   
- fail:


- name: Install and configure MySQL

  hosts
: mysql
  sudo
: yes
  roles
:
   
- mysql
  tags
: mysql


But couldn't find anything printed into /tmp/ansible_default_ipv4.yaml anywhere.  ( Now I could have mocked it up given how green I am with this. )

However, I've also done this:

# cat tasks/variables.yml
---


- name: Include OS-specific variables (RedHat) .
  include_vars
: "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
 
when: ansible_os_family == "RedHat"


- name: Define mysql_config_file variable .
  set_fact
:
    mysql_config_file
: "{{ __mysql_config_file }}"
 
when: mysql_config_file is not defined


- debug:
    msg
: "var = {{ ansible_default_ipv4.address }}"
 
when: ansible_default_ipv4.address is defined


- name: Define the mysql_ipv4 variable
  set_fact
:
    mysql_ipv4
: "{{ ansible_default_ipv4.address }}"
 
when: mysql_ipv4 is not defined


- name: Print all variables for each remote device
  debug
:
   
var: hostvars[inventory_hostname]


which printed this output (snippet only):

TASK [mysql : Print all variables for each remote device] *************************************************************************************************
task path
: /ansible/roles/mysql/tasks/variables.yml:21
ok
: [mysql04] => {
   
"hostvars[inventory_hostname]": {
       
"__mysql_config_file": "/etc/my.cnf",
       
"ansible_all_ipv4_addresses": [
           
"192.168.0.109"
       
],
       
"ansible_all_ipv6_addresses": [
           
"fe80::250:56ff:fe86:e11b"
       
],
       
"ansible_apparmor": {
           
"status": "disabled"
       
},
       
"ansible_architecture": "x86_64",
       
"ansible_bios_date": "04/14/2014",
       
"ansible_bios_version": "6.00",
       
"ansible_check_mode": true,
       
"ansible_cmdline": {
           
"BOOT_IMAGE": "/vmlinuz-3.10.0-693.21.1.el7.x86_64",
           
"LANG": "en_US.UTF-8",
           
"biosdevname": "0",
           
"crashkernel": "auto",
           
"net.ifnames": "0",
           
"quiet": true,
           
"rd.lvm.lv": "centos/swap",
           
"rhgb": true,
           
"ro": true,
           
"root": "/dev/mapper/centos-root"
       
},
       
"ansible_date_time": {
           
"date": "2018-11-04",
           
"day": "04",
           
"epoch": "1541340261",
           
"hour": "09",
           
"iso8601": "2018-11-04T14:04:21Z",
           
"iso8601_basic": "20181104T090421500144",
           
"iso8601_basic_short": "20181104T090421",
           
"iso8601_micro": "2018-11-04T14:04:21.500460Z",
           
"minute": "04",
           
"month": "11",
           
"second": "21",
           
"time": "09:04:21",
           
"tz": "EST",
           
"tz_offset": "-0500",
           
"weekday": "Sunday",
           
"weekday_number": "0",
           
"weeknumber": "44",
           
"year": "2018"

       
},
       
"ansible_default_ipv4": {
           
"address": "192.168.0.109",
           
"alias": "eth0",
           
"broadcast": "192.168.0.255",

           
"gateway": "192.168.0.1",
           
"interface": "eth0",
           
"macaddress": "00:50:56:86:e1:1b",
           
"mtu": 1500,
           
"netmask": "255.255.255.0",
           
"network": "192.168.0.0",
           
"type": "ether"
       
},



Tom K.

unread,
Nov 4, 2018, 9:28:12 AM11/4/18
to Ansible Project


On Sunday, November 4, 2018 at 1:35:14 AM UTC-5, Vladimir Botka wrote:
"HostVarsVars" looks suspicious in the error message. Where does it come from? Find it and check if this is what you want.

It only shows up in the output:

[root@awx01 ansible]# grep -EiR HostVarsVars *
[root@awx01 ansible]#

so thinking this comes from the ansible python code itself.  Googling that shows results meaning others receive the same "HostVarsVars" name in the output leading me to believe it's legit?  I found it odd that it prints HostVars (with two Vars) instead of one but maybe that's not what you were pointing too?

Uwe Sauter

unread,
Nov 4, 2018, 9:51:24 AM11/4/18
to ansible...@googlegroups.com
Did you check /tmp on your mysql host? This will copy 'content' to the destination on the target host, not on the host
running the playbook.



Am 04.11.18 um 15:22 schrieb Tom K.:
>   gather_facts:false
>   tasks:
> -name:Dumpansible_default_ipv4 variable output
>       copy:
>         dest:/tmp/ansible_default_ipv4.yaml
>         content:'{{ ansible_default_ipv4 | to_nice_yaml }}'
> -fail:
>
>
> -name:Installandconfigure MySQL
>   hosts:mysql
>   sudo:yes
>   roles:
> -mysql
>   tags:mysql
>
> |
>
> But couldn't find anything printed into /tmp/ansible_default_ipv4.yaml anywhere.  ( Now I could have mocked it up given
> how green I am with this. )
>
> However, I've also done this:
>
> |
> # cat tasks/variables.yml
> ---
>
>
> -name:IncludeOS-specific variables (RedHat).
>   include_vars:"{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
> when:ansible_os_family =="RedHat"
>
>
> -name:Definemysql_config_file variable .
>   set_fact:
>     mysql_config_file:"{{ __mysql_config_file }}"
> when:mysql_config_file isnotdefined
>
>
> -debug:
>     msg:"var = {{ ansible_default_ipv4.address }}"
> when:ansible_default_ipv4.address isdefined
>
>
> -name:Definethe mysql_ipv4 variable
>   set_fact:
>     mysql_ipv4:"{{ ansible_default_ipv4.address }}"
> when:mysql_ipv4 isnotdefined
>
>
> -name:Printall variables foreach remote device
>   debug:
> var:hostvars[inventory_hostname]
>
> |
>
> which printed this output (snippet only):
>
> |
> TASK [mysql :Printall variables foreach remote
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer>.

Uwe Sauter

unread,
Nov 4, 2018, 9:51:48 AM11/4/18
to ansible...@googlegroups.com
As the error message state, 'HostVarsVars' is an Python object. Without looking into the source code I suspect it to be
some kind of Class inside the HostVars object that holds the actual values you can access via
hostvars[inventory_hostname]["key"].

Am 04.11.18 um 15:28 schrieb Tom K.:
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/45b366f5-5e62-44ad-b23b-7fba430ec01d%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/45b366f5-5e62-44ad-b23b-7fba430ec01d%40googlegroups.com?utm_medium=email&utm_source=footer>.

Uwe Sauter

unread,
Nov 4, 2018, 10:03:49 AM11/4/18
to ansible...@googlegroups.com
OK, more comments:

>
> So I've modified the first main.yml as follows:
>
> |
> # cat main.yml
> ---
>
>
> -name:Gatherall facts prior to execution
>   hosts:mysql
>   gather_facts:false

Not gathering facts here will lead you to miss many of the ansible_* variables.

>   tasks:
> -name:Dumpansible_default_ipv4 variable output
>       copy:

The result of the copy module can be found on the target host(s), not on the host running the playbook. But in this case
it should already fail as you don't gather facts and thus miss ansible_default_ipv4.

Try the following:



#### test.yaml ####
---
- name: test templating
hosts: mysql
gather_facts: true
tasks:
- debug: msg='{{ inventory_hostname }} has default IP {{ ansible_default_ipv4["address"] }}
- template:
src: test.j2
dest: /tmp/test.out

#### end test.yaml ####

#### test.j2 ####
# {{ ansible_managed }}
My default IPv4 address is: {{ ansible_default_ipv4["address"] }}

My other hostvars are:
{{ hostvars[inventory_hostname] | to_nice_yaml }}
#### end test.j2 ####

You should get a debug output for each of your hosts and there should be a /tmp/test.out on each of your hosts from the
mysql group.



>         dest:/tmp/ansible_default_ipv4.yaml
>         content:'{{ ansible_default_ipv4 | to_nice_yaml }}'
> -fail:
>
>
> -name:Installandconfigure MySQL
>   hosts:mysql
>   sudo:yes
>   roles:
> -mysql
>   tags:mysql
>
> |
>
> But couldn't find anything printed into /tmp/ansible_default_ipv4.yaml anywhere.  ( Now I could have mocked it up given
> how green I am with this. )
>
> However, I've also done this:
>
> |
> # cat tasks/variables.yml
> ---
>
>
> -name:IncludeOS-specific variables (RedHat).
>   include_vars:"{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
> when:ansible_os_family =="RedHat"
>
>
> -name:Definemysql_config_file variable .
>   set_fact:
>     mysql_config_file:"{{ __mysql_config_file }}"
> when:mysql_config_file isnotdefined
>
>
> -debug:
>     msg:"var = {{ ansible_default_ipv4.address }}"
> when:ansible_default_ipv4.address isdefined
>
>
> -name:Definethe mysql_ipv4 variable
>   set_fact:
>     mysql_ipv4:"{{ ansible_default_ipv4.address }}"
> when:mysql_ipv4 isnotdefined
>
>
> -name:Printall variables foreach remote device
>   debug:
> var:hostvars[inventory_hostname]
>
> |
>
> which printed this output (snippet only):
>
> |
> TASK [mysql :Printall variables foreach remote
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer>.

Tom K.

unread,
Nov 4, 2018, 10:04:07 AM11/4/18
to Ansible Project


On Sunday, November 4, 2018 at 9:51:24 AM UTC-5, Uwe Sauter wrote:
Did you check /tmp on your mysql host? This will copy 'content' to the destination on the target host, not on the host
running the playbook.



I did actually: 

[root@mysql04 tmp]# ls -altri /tmp/ansible_default_*
ls
: cannot access /tmp/ansible_default_*: No such file or directory
[root@mysql04 tmp]#


I checked all hosts including the two ansible cluster ones ( awx01, awx02 ).  No such file.
 

Tom K.

unread,
Nov 4, 2018, 10:16:20 AM11/4/18
to Ansible Project
[root@awx02 mysql]# pwd
/ansible/roles/mysql
[root@awx02 mysql]#  cat templates/test.j2

# {{ ansible_managed }}
My default IPv4 address is: {{ ansible_default_ipv4["address"] }}


My other hostvars are:
{{ hostvars[inventory_hostname] | to_nice_yaml }}
[root@awx02 mysql]#


[root@awx01 ansible]# pwd
/ansible
[root@awx01 ansible]# cat main.yml
---
- name: Gather all facts prior to execution
  hosts
: mysql
  gather_facts
: true

  tasks
:
   
- debug: msg='{{ inventory_hostname }} has default IP {{ ansible_default_ipv4["address"] }}'
   
- template:
        src
: test.j2
        dest
: /tmp/test.out


- name: Install and configure MySQL

  hosts
: mysql
  sudo
: yes
  roles
:
   
- mysql
  tags
: mysql


[root@awx01 ansible]#


[root@mysql04 tmp]# ls -altri /tmp/test*
ls
: cannot access /tmp/test*: No such file or directory
[root@mysql04 tmp]#


[root@awx01 ansible]# ls -altri /tmp/test*
ls
: cannot access /tmp/test*: No such file or directory
[root@awx01 ansible]#



Don't think I got it right on though because it printed nothing:

PLAY [Gather all facts prior to execution] ****************************************************************************************************************


TASK
[Gathering Facts] ************************************************************************************************************************************
task path
: /ansible/main.yml:2


 

Uwe Sauter

unread,
Nov 4, 2018, 10:20:56 AM11/4/18
to ansible...@googlegroups.com
Would you mind sending the complete output of

ansible-playbook main.yaml -vvv

?

Am 04.11.18 um 16:16 schrieb Tom K.:
> Myother hostvars are:
> {{hostvars[inventory_hostname]|to_nice_yaml }}
> [root@awx02 mysql]#
> |
>
>
> |
> [root@awx01 ansible]# pwd
> /ansible
> [root@awx01 ansible]# cat main.yml
> ---
> -name:Gatherall facts prior to execution
>   hosts:mysql
>   gather_facts:true
>   tasks:
> -debug:msg='{{ inventory_hostname }} has default IP {{ ansible_default_ipv4["address"] }}'
> -template:
>         src:test.j2
>         dest:/tmp/test.out
>
>
> -name:Installandconfigure MySQL
>   hosts:mysql
>   sudo:yes
>   roles:
> -mysql
>   tags:mysql
>
>
> [root@awx01 ansible]#
>
> |
>
> |
> [root@mysql04 tmp]# ls -altri /tmp/test*
> ls:cannot access /tmp/test*:Nosuch file ordirectory
> [root@mysql04 tmp]#
>
>
> [root@awx01 ansible]# ls -altri /tmp/test*
> ls:cannot access /tmp/test*:Nosuch file ordirectory
> [root@awx01 ansible]#
>
> |
>
>
> Don't think I got it right on though because it printed nothing:
>
> |
> PLAY [Gatherall facts prior to
> execution]****************************************************************************************************************
>
>
> TASK
> [GatheringFacts]************************************************************************************************************************************
> > "rd.lvm.lv <http://rd.lvm.lv>":"centos/swap",
> > ansible-proje...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> > To post to this group, send email to ansible...@googlegroups.com <javascript:>
> <mailto:ansible...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> > For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com?utm_medium=email&utm_source=footer>.

Tom K.

unread,
Nov 4, 2018, 10:25:28 AM11/4/18
to Ansible Project


On Sunday, November 4, 2018 at 10:20:56 AM UTC-5, Uwe Sauter wrote:
Would you mind sending the complete output of

ansible-playbook main.yaml -vvv

?



I got a result now but need to continue this in a bit as I need to step away:

[root@mysql04 tmp]# cat /tmp/test.out|grep -Ei ansible_default_ipv4 -A5 -B5
    tz_offset
: '-0500'
    weekday
: Sunday
    weekday_number
: '0'
    weeknumber
: '44'
    year
: '2018'
ansible_default_ipv4
:
    address
: 192.168.0.109
   
alias: eth0
    broadcast
: 192.168.0.255
    gateway
: 192.168.0.1
   
interface: eth0
[root@mysql04 tmp]#


Still same message:

fatal: [mysql04]: FAILED! => {
   
"changed": false,
   
"msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'"
}


ansible-playbook -i infra --limit mysql04 main.yml --tags "mysql" -vvv



[root@awx01 ansible]# cat main.yml
---
- name: Gather all facts prior to execution
  hosts
: mysql
  gather_facts
: true
  tasks
:

   
- debug: msg='{{ inventory_hostname }} has default IP {{ ansible_default_ipv4["address"] }}'
   
- template:
        src
: test.j2
        dest
: /tmp/test.out

  tags
: mysql


- name: Install and configure MySQL
>      > ansible-proje...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.
>      > To post to this group, send email to ansible...@googlegroups.com <javascript:>
>     <mailto:ansible...@googlegroups.com <javascript:>>.
>      > To view this discussion on the web visit
>      > https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com>
>      >
>     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>      > For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to

Uwe Sauter

unread,
Nov 4, 2018, 10:32:29 AM11/4/18
to ansible...@googlegroups.com
Does the first line of /tmp/test.out contain the correct IP address? If so, templating is working correctly.

Also please keep in mind that we are no mind readers and stripping away context to make output shorter usually doesn't
help. That said please provide the complete output of a run with -vvv.


Am 04.11.18 um 16:25 schrieb Tom K.:
> -name:Gatherall facts prior to execution
>   hosts:mysql
>   gather_facts:true
>   tasks:
> -debug:msg='{{ inventory_hostname }} has default IP {{ ansible_default_ipv4["address"] }}'
> -template:
>         src:test.j2
>         dest:/tmp/test.out
>   tags:mysql
> >      > "rd.lvm.lv <http://rd.lvm.lv> <http://rd.lvm.lv>":"centos/swap",
> >      > ansible-proje...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com
> <javascript:> <javascript:>>.
> >      > To post to this group, send email to ansible...@googlegroups.com <javascript:>
> >     <mailto:ansible...@googlegroups.com <javascript:>>.
> >      > To view this discussion on the web visit
> >      > https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com>
> >     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com>>
> >      >
> >
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer>
>
> >
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer>>>.
>
> >
> >      > For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>
> <https://groups.google.com/d/optout <https://groups.google.com/d/optout>>.
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to
> > ansible-proje...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> > To post to this group, send email to ansible...@googlegroups.com <javascript:>
> <mailto:ansible...@googlegroups.com <javascript:>>.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com>
> >
> <https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> > For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/935752e8-4300-436b-9c0b-f2c1cf1967e2%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/935752e8-4300-436b-9c0b-f2c1cf1967e2%40googlegroups.com?utm_medium=email&utm_source=footer>.

Tom K.

unread,
Nov 4, 2018, 5:50:01 PM11/4/18
to Ansible Project
Hey Uwe,

I hear you and apologies.  Was trying to keep it from getting too messy since the output is large.  


Just the same, in case you can't get to the file, here's the first 100 lines:   


TASK [mysql : Print all variables for each remote device] *************************************************************************************************
task path: /ansible/roles/mysql/tasks/variables.yml:21
ok: [mysql04] => {
    "hostvars[inventory_hostname]": {
        "__mysql_config_file": "/etc/my.cnf",
        "ansible_all_ipv4_addresses": [
            "192.168.0.109"
        ],
        "ansible_all_ipv6_addresses": [
            "fe80::250:56ff:fe86:e11b"
        ],
        "ansible_apparmor": {
            "status": "disabled"
        },
        "ansible_architecture": "x86_64",
        "ansible_bios_date": "04/14/2014",
        "ansible_bios_version": "6.00",
        "ansible_check_mode": false,
        "ansible_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-3.10.0-693.21.1.el7.x86_64",
            "LANG": "en_US.UTF-8",
            "biosdevname": "0",
            "crashkernel": "auto",
            "net.ifnames": "0",
            "quiet": true,
            "rd.lvm.lv": "centos/swap",
            "rhgb": true,
            "ro": true,
            "root": "/dev/mapper/centos-root"
        },
        "ansible_date_time": {
            "date": "2018-11-04",
            "day": "04",
            "epoch": "1541369584",
            "hour": "17",
            "iso8601": "2018-11-04T22:13:04Z",
            "iso8601_basic": "20181104T171304330516",
            "iso8601_basic_short": "20181104T171304",
            "iso8601_micro": "2018-11-04T22:13:04.330753Z",
            "minute": "13",
            "month": "11",
            "second": "04",
            "time": "17:13:04",
>     <javascript:> <javascript:>>.
>      >      > To post to this group, send email to ansible...@googlegroups.com <javascript:>
>      >     <mailto:ansible...@googlegroups.com <javascript:>>.
>      >      > To view this discussion on the web visit
>      >      > https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com>
>      >     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com>>
>      >      >
>      >    
>     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer>
>
>      >    
>     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/7d79d7d6-ed2f-4693-8182-94ef9bd62c7b%40googlegroups.com?utm_medium=email&utm_source=footer>>>.
>
>      >
>      >      > For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>
>     <https://groups.google.com/d/optout <https://groups.google.com/d/optout>>.
>      >
>      > --
>      > You received this message because you are subscribed to the Google Groups "Ansible Project" group.
>      > To unsubscribe from this group and stop receiving emails from it, send an email to
>      > ansible-proje...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.
>      > To post to this group, send email to ansible...@googlegroups.com <javascript:>
>     <mailto:ansible...@googlegroups.com <javascript:>>.
>      > To view this discussion on the web visit
>      > https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com>
>      >
>     <https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/c2f987b7-d1af-4739-9fc4-5c573f436ab8%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>      > For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to

Kai Stian Olstad

unread,
Nov 5, 2018, 9:07:09 AM11/5/18
to ansible...@googlegroups.com
On 04.11.2018 23:50, Tom K. wrote:
> Hey Uwe,
>
> I hear you and apologies. Was trying to keep it from getting too messy
> since the output is large.
>
> Link to file is
> here: http://microdevsys.com/ansible/ansible-vvv.out.txt.gz
>
> Just the same, in case you can't get to the file, here's the first 100
> lines:
>
>
> TASK [mysql : Print all variables for each remote device]
> *************************************************************************************************
> task path: /ansible/roles/mysql/tasks/variables.yml:21
> ok: [mysql04] => {

Why do you think the errors is related to mysql04?

Your template you have this code

{% for host in groups['mysql']%}
{{hostvars[host]['ansible_default_ipv4']['address']}}{% if not
loop.last %},{% endif %}
{% endfor %}

The host is looping over every host is the group mysql and getting the
ansible_default_ipv4, so anyone of them could be the culprit.
So you need to check them all, the easiest way to do that would be:

ansible mysql -m setup -a 'filter=ansible_default_ipv4'

--
Kai Stian Olstad

Uwe Sauter

unread,
Nov 5, 2018, 9:09:09 AM11/5/18
to ansible...@googlegroups.com
Because he was running the playbook with this commandline:

ansible-playbook -i infra --limit mysql04 main.yml --tags "mysql" -vvv


Am 05.11.18 um 15:06 schrieb Kai Stian Olstad:

Kai Stian Olstad

unread,
Nov 5, 2018, 9:18:22 AM11/5/18
to ansible...@googlegroups.com
On 05.11.2018 15:08, Uwe Sauter wrote:
> Because he was running the playbook with this commandline:
>
> ansible-playbook -i infra --limit mysql04 main.yml --tags "mysql" -vvv

There you have the problem.
He has template code that read variable from all the host in group mysql
and running the command with limit.
Because of limit the fact gathering will run on mysql04 and not the
other hosts in the group so the ['ansible_default_ipv4']['address'] will
be undefined for all of them except mysql04.

--
Kai Stian Olstad

Uwe Sauter

unread,
Nov 5, 2018, 9:39:03 AM11/5/18
to ansible...@googlegroups.com
Sure, but the template will only be used for the one host and as such should not look for variables of other hosts, right?


Am 05.11.18 um 15:18 schrieb Kai Stian Olstad:

Kai Stian Olstad

unread,
Nov 5, 2018, 9:52:15 AM11/5/18
to ansible...@googlegroups.com
On Monday, 5 November 2018 15:38:51 CET Uwe Sauter wrote:
> Sure, but the template will only be used for the one host and as such should not look for variables of other hosts, right?

It will look up the variable on all host in group mysql

This is the code in the template

{% for host in groups['mysql']%}
{{hostvars[host]['ansible_default_ipv4']['address']}}{% if not loop.last %},{% endif %}
{% endfor %}

In the inventory he has
[mysql]
mysql01
mysql02
mysql03
mysql04

In the first iteration host = mysql01 so he is running
{{ hostvars['mysql01']['ansible_default_ipv4']['address'] }}

But since gather fact has not been run this will get you the error undefined variable.


--
Kai Stian Olstad


Uwe Sauter

unread,
Nov 5, 2018, 10:06:30 AM11/5/18
to ansible...@googlegroups.com
As far as I can tell there is no such loop in the template:


[root@awx02 mysql]# cat templates/my.cnf.j2
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
binlog_format=ROW
bind-address="{{ ansible_default_ipv4.address }}"
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=122M
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
wsrep_cluster_name="galera_cluster1"
wsrep_cluster_address="gcomm://{% for host in
groups['mysql']%}{{hostvars[host]['ansible_default_ipv4']['address']}}{%
if not loop.last %},{% endif %}{% endfor %}"
wsrep_sst_method=rsync
server_id=1
wsrep_node_address="{{ ansible_default_ipv4.address }}"
wsrep_node_name="{{ ansible_hostname }}"
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


From which message did you get that loop in the template?




Am 05.11.18 um 15:51 schrieb Kai Stian Olstad:

Kai Stian Olstad

unread,
Nov 5, 2018, 10:18:59 AM11/5/18
to ansible...@googlegroups.com
On Monday, 5 November 2018 16:06:19 CET Uwe Sauter wrote:
> As far as I can tell there is no such loop in the template:

It is, i just formatted it to show it more clearly.


> [root@awx02 mysql]# cat templates/my.cnf.j2
> [mysqld]
> datadir=/var/lib/mysql
> socket=/var/lib/mysql/mysql.sock
> user=mysql
> binlog_format=ROW
> bind-address="{{ ansible_default_ipv4.address }}"
> default_storage_engine=innodb
> innodb_autoinc_lock_mode=2
> innodb_flush_log_at_trx_commit=0
> innodb_buffer_pool_size=122M
> wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
> wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
> wsrep_cluster_name="galera_cluster1"
> wsrep_cluster_address="gcomm://{% for host in
> groups['mysql']%}{{hostvars[host]['ansible_default_ipv4']['address']}}{%
> if not loop.last %},{% endif %}{% endfor %}"

The loop is here.


> wsrep_sst_method=rsync
> server_id=1
> wsrep_node_address="{{ ansible_default_ipv4.address }}"
> wsrep_node_name="{{ ansible_hostname }}"
> [mysql_safe]
> log-error=/var/log/mysqld.log
> pid-file=/var/run/mysqld/mysqld.pid
>
>
> From which message did you get that loop in the template?

See above.


--
Kai Stian Olstad


Uwe Sauter

unread,
Nov 5, 2018, 10:23:26 AM11/5/18
to ansible...@googlegroups.com
Ah, I missed that line.

Thanks.


Am 05.11.18 um 16:18 schrieb Kai Stian Olstad:

Tom K.

unread,
Nov 13, 2018, 3:10:18 AM11/13/18
to Ansible Project
Sorry for the late reply.  We might have lost track of the original error.  mysql0[1-3] are ok and print all variables.  Only host mysql04 prints the undefined variable.  (see above).  Going to do more tests on your suggestions and see further.  Included a few of the modifications Uwe pointed out as well. My Ansible version:

[root@awx01 ansible]# rpm -aq|grep -Ei ansible
ansible
-inventory-grapher-2.4.4-1.el7.noarch
ansible
-lint-3.4.21-1.el7.noarch
ansible
-review-0.13.4-1.el7.noarch
ansible
-doc-2.5.3-1.el7.noarch
ansible
-2.7.0-1.el7.noarch
[root@awx01 ansible]#

 


--
Kai Stian Olstad


Tom K.

unread,
Nov 14, 2018, 8:49:16 AM11/14/18
to Ansible Project
Ok.  So I removed a couple of tags from the mysql task "mysql : Copy my.cnf global MySQL configuration."  and adjusted the play as follows:

[root@awx01 ansible]# vi main.yml
---
- name: Gather all facts prior to execution
  hosts
: mysql
  gather_facts
: true
  tasks
:

   
- debug: msg='{{ inventory_hostname }} has default IP {{ ansible_default_ipv4["address"] }}'
   
- template:
        src
: test.j2
        dest
: /tmp/test.out

  tags
: mysql


- name: Install and configure MySQL
  hosts
:
mysql
  become
: true

  roles
:
   
- mysql
  tags
: mysql


But that didn't work.  Still got the original error with mysql04.  Until I removed mysql01-3 from the infra file leaving only mysql04:

[mysql]
mysql04


And reran using:

ansible-playbook -i infra --limit mysql04 main.yml --tags "mysql" -v

And this time everything worked fine.  So I put the other mysql servers back in the list:

[mysql]
mysql01
mysql02
mysql03
mysql04


And reran the same ansible-playbook line as above getting the same error again:

TASK [mysql : Copy my.cnf global MySQL configuration.] *****************************************************************************************************

fatal
: [mysql04]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'"}

        to
retry, use: --limit @/ansible/main.retry


PLAY RECAP
*************************************************************************************************************************************************
mysql04                    
: ok=13   changed=1    unreachable=0    failed=1


[root@awx01 ansible]#


But it clearly get's the IP at the top of the verbose printout:

TASK [debug] ***********************************************************************************************************************************************
ok
: [mysql04] => {
   
"msg": "mysql04 has default IP 192.168.0.109"
}


I tried to put a space at the end of infra behind mysql04, no effect.  Tried a few other combinations including changing the position where mysql04 appears.  Nothing.  Appears that unless mysql04 is the ONLY element in the host group [mysql], it doesn't work. 

Kai Stian Olstad

unread,
Nov 14, 2018, 9:15:38 AM11/14/18
to ansible...@googlegroups.com
On 14.11.2018 14:49, Tom K. wrote:
> On Tuesday, November 13, 2018 at 3:10:18 AM UTC-5, Tom K. wrote:
>
> Ok. So I removed a couple of tags from the mysql task "mysql : Copy
> my.cnf
> global MySQL configuration." and adjusted the play as follows:

The playbook is fine, the problem is the limit option your are using on
ansible-playbook.
You still have the same problem I commented on earlier.

When you run a with --limit, the task and *gather_facts* is only run on
host specified in the limit.
So when you in you template try using facts for mysql01-03 they don't
exist since you haven't gather them so you get the error message.

So remove you --limit and it will work, the template you have will never
work if you specify limit.


--
Kai Stian Olstad

Stephen C.

unread,
Nov 16, 2018, 5:53:32 AM11/16/18
to Ansible Project
Hi Tom, 

Can you try a couple of options and post it to this thread please ? 
With the same inventory file: 

[mysql]
  mysql01
  mysql02
  mysql03
  mysql04



ansible-playbook -i infra --limit mysql02 main.yml --tags "mysql" -v

ansible
-playbook -i infra --limit mysql03 main.yml --tags "mysql" -v


Thnx, 
Stephen

Tom K.

unread,
Nov 19, 2018, 1:34:17 AM11/19/18
to Ansible Project
So I've made two more empty hosts and called them mysql05 and mysql06 and tested on all 3 (this way I don't blow away my working cluster).  Now I removed the limit flag and run it like this:

# ansible-playbook -i infra main.yml --tags "mysql" -v

Everything worked well and the /etc/my.cnf was populated as expected:

[root@mysql04 ~]# cat /etc/my.cnf

[mysqld]
datadir
=/var/lib/mysql
socket
=/var/lib/mysql/mysql.sock
user
=mysql
binlog_format
=
ROW
bind
-address="192.168.0.109"

default_storage_engine
=innodb
innodb_autoinc_lock_mode
=2
innodb_flush_log_at_trx_commit
=0
innodb_buffer_pool_size
=122M
wsrep_provider
=/usr/lib64/galera-3/libgalera_smm.so
wsrep_provider_options
="gcache.size=300M; gcache.page_size=300M"
wsrep_cluster_name
="galera_cluster1"

wsrep_cluster_address
='gcomm://192.168.0.109,192.168.0.102,192.168.0.111'
wsrep_sst_method
=rsync
server_id
=1
wsrep_node_address
="192.168.0.109"
wsrep_node_name
="mysql04"
[mysql_safe]
log
-error=/var/log/mysqld.log
pid
-file=/var/run/mysqld/mysqld.pid
[root@mysql04 ~]#


Still, running the limit on any one, as Stephen suggested, fails with the following for any host specified by limit as you mentioned:


ansible-playbook -i infra --limit mysql05 main.yml --tags "mysql" -v --check

fatal
: [mysql05]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'"}


ansible-playbook -i infra --limit mysql06 main.yml --tags "mysql" -v --check

fatal
: [mysql06]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'"}

But it seems to work opposite to the way described above (Apologies if I'm misreading).  The error is thrown for ANY host that I use the --limit flag on, not the ones that I don't use the limit on.  

I would have expected it to gather facts on the host I'm limiting the run too, not the ones I'm excluding.  

Cheers,
Tom

Kai Stian Olstad

unread,
Nov 19, 2018, 9:24:16 AM11/19/18
to ansible...@googlegroups.com
On Monday, 19 November 2018 07:34:17 CET Tom K. wrote:
> ansible-playbook -i infra --limit mysql06 main.yml --tags "mysql" -v --check
>
> fatal: [mysql06]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable:
> 'ansible.vars.hostvars.HostVarsVars object' has no attribute
> 'ansible_default_ipv4'"}
>
> But it seems to work opposite to the way described above (Apologies if I'm
> misreading). The error is thrown for ANY host that I use the *--limit*
> flag on, not the ones that I don't use the limit on.
>
> I would have expected it to gather facts on the host I'm limiting the run
> too, not the ones I'm excluding.

Yes, it's only gathering facts on the host in the limit.

The error message isn't about that it can't find ansible_default_ipv4 on the host in the limit (mysql06), it's about mysql06 cant find ansible_default_ipv4 for host mysql05.


--
Kai Stian Olstad


Tom K.

unread,
Nov 19, 2018, 8:24:57 PM11/19/18
to Ansible Project
Kool.  So it's really saying (bolded):

ansible-playbook -i infra --limit mysql06 main.yml --tags "mysql" ---
check

fatal
: [mysql06]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4' for mysql05."}

Makes sense.  Ty.

Cheers,
TK
Reply all
Reply to author
Forward
0 new messages