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

On Friday, November 16, 2018 at 5:53:32 AM UTC-5, Stephen C. wrote:
>
> 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
>
> On Wednesday, November 14, 2018 at 9:15:38 AM UTC-5, Kai Stian Olstad 
> wrote:
>>
>> 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. 
>>
>>
>> > [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 
>>
>>
>> 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 
>>
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a7a99a33-69d4-4d0b-8dc1-7b76a727a9b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to