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

2018-11-03 Thread Vladimir Botka
"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

-- 
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/162180ee-8886-41a2-b4d1-c9cde3d495fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-11-03 Thread Tom K.
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

-- 
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/a1246cf1-4828-477b-aa38-5c8109c334a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Reinstall package if config dir is missing or different?

2018-11-03 Thread Dick Visser
On Fri, 2 Nov 2018 at 17:15, Mauricio Tavares  wrote:

> (https://docs.ansible.com/ansible/latest/modules/package_module.html)
> can't be forced. Yeah, I am trying to abstract as much as possible. I
> guess I will try to uninstall and then reinstall package manually

Example playbook below will do that.
Initially it used the 'stat' module for each file, but since it's very
common for packages to have hundreds of files that became too slow.
So as a workaround I replaced it with a single command task that calls
stat on all files at once.
The Debian/RedHat test is very basic.
Pass the package name as command line option ( -e package=httpd).


- name: Ensure package is correctly installed
  become: true
  hosts: all
  tasks:

- name: Ensure package is installed
  package:
name: "{{ package }}"

- name: Find package's files
  command: "{{ (ansible_os_family == 'Debian') | ternary( 'dpkg
--listfiles', 'repoquery --list') }} {{ package }}"
  register: pkg_files
  changed_when: false

- name: Stat all files
  command: "stat {{ pkg_files.stdout_lines | join(' ') }}"
  changed_when: false
  failed_when: false
  register: stat_all_files

- name: Force reinstall
  command: "{{ (ansible_os_family == 'Debian') | ternary( 'apt-get
install --', 'yum -y ') }}reinstall {{ package }}"
  args:
warn: false
  when: stat_all_files.rc != 0




Dick

-- 
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/CAL8fbwOH8a-u%3D4_6%3DQScfad7ZhBXuSqELqsFMF3nCPUzU1dPNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-11-03 Thread Uwe Sauter

Could you show us the play where this happens?


Am 03.11.18 um 21:18 schrieb Tom K.:

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.

--
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/bcff4644-fba3-4efe-9434-4b20465d1cd0%40googlegroups.com 
.

For more options, visit 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-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/946f683c-4459-1c17-ed95-24d7d94857c4%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] hostvars[some_ip] does not contain `ansible_hostname`

2018-11-03 Thread Uwe Sauter

In order to access some ansible_* variables you need to gather facts on the 
host before.

See e.g. 
https://stackoverflow.com/questions/45908067/whats-the-difference-between-inventory-hostname-and-ansible-hostname

Am 03.11.18 um 21:15 schrieb Barry Kaplan:

Why would this be? It has lots and lots of ansible_* variables, but some others 
like ansible_hostname or ansible_mounts.

This is not the case for hosts though, just some.

--
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/93639896-f6e0-413b-bb24-e74f7413c0aa%40googlegroups.com 
.

For more options, visit 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-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/89765638-b237-6df8-0da2-5f019a8a3553%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-11-03 Thread Tom K.


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.


-- 
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/bcff4644-fba3-4efe-9434-4b20465d1cd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] hostvars[some_ip] does not contain `ansible_hostname`

2018-11-03 Thread Barry Kaplan
Why would this be? It has lots and lots of ansible_* variables, but some 
others like ansible_hostname or ansible_mounts.

This is not the case for hosts though, just some.

-- 
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/93639896-f6e0-413b-bb24-e74f7413c0aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Undefined variable when using lookup('dict', hostvars) or map('extract', hostvars)

2018-11-03 Thread Barry Kaplan
Here is what I did to get my results. Seems smelly but works.

- debug:
msg:
  - "{{ item }}"
  with_subelements:
- "{{ groups[host_group] | map('extract', hostvars) | 
dicts_pick(['ec2_id', 'ansible_hostname', 'ansible_mounts']) }}"
- 'ansible_mounts'

with a custom filter

def dicts_pick(dicts, keys):
results = []
for d in dicts:
results.append({k: d[k] for k in keys})
return results




-- 
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/4092670e-5f49-4fe9-90b8-eaf469ffe4ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Undefined variable when using lookup('dict', hostvars) or map('extract', hostvars)

2018-11-03 Thread Barry Kaplan
I'm trying to extract a few values from hostvars for subset of hosts, eg:

- debug:
msg:
  - "just a string"  # a constant just to show the problem is not here
  loop: "{{ lookup('dict', hostvars) }}"
  when: "item.key in groups['mygroup']"

or 
 
- debug:
msg:
  - "just a string"  # a constant just to show the problem is not here
  loop: "{{ groups[host_group] | map('extract', hostvars) | list }}"

when either of these run I get errors like

TASK [debug] 
***
fatal: [localhost]: FAILED! => {"msg": "'ansible_memtotal_mb' is undefined"}
to retry, use: --limit @/Users/bkaplan/.ansible/retry-files/ops-elk.
retry


Where the undefined variable could be anything that might be in the huge 
set of variables for a host.

This seems to imply that lookup('dict') and map('extract') are trying to 
eagerly resolve the variables.

Is this expected? Why would these lookups so aggressively inspect the 
entire dict?

-- 
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/c9a80dde-dea2-477f-afd2-225fa02c114d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Restart kestrelservice

2018-11-03 Thread Dick Visser
The whole point of the systemd module (or any other module, really) is to
abstract commands away, so don’t have to use them.
Try out the examples and enjoy!

Dick


On Fri, 2 Nov 2018 at 19:39, Nk Chitturi  wrote:

> Brian, I am very new to anisble but in the link you provided i can see
> some examples with systemd, it has state mentioned, but how can i use
> command to restart the service
>
> - name: restart service cron on centos, in all cases, also issue 
> daemon-reload to pick up config changes
>   systemd:
> state: restarted
> daemon_reload: yes
> name: crond
>
>
> On Fri, Nov 2, 2018 at 11:34 AM Brian Coca  wrote:
>
>> See docs for correct syntax
>> https://docs.ansible.com/ansible/latest/modules/systemd_module.html
>>
>> --
>> --
>> Brian Coca
>>
>> --
>> 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/CACVha7fSY2NAmSoNTJg9ohOL8RGvLJjhdr2z83Ae6hxCExd1Kw%40mail.gmail.com
>> .
>> For more options, visit 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-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/CABdF8S0uppa%2Bti%2B44jHtMVO5GUJsJ8yjtqn-%3DTz8r1f0LUPmJw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Sent from a mobile device - please excuse the brevity, spelling and
punctuation.

-- 
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/CAL8fbwPV46cC-UqeGpDBUVEYBN5RtfOVU4ofx1m1eBzzOaVQ7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.