Re: [ansible-project] Determining the primary IP address

2021-10-21 Thread John Petro
Ok.. so some more info...  I think I have a workable solution.  I"ll be
testing it tomorrow, but I am 99% sure I have it figured out.  The code
above, actually didn't work as I thought..  so, I changed this:

  when: hostvars[inventory_hostname]['ansible_default_ipv4']['address'] |
select('match', '^10.[0-9]+')

to this:
when: hostvars[inventory_hostname]['ansible_default_ipv4']['address'] |
regex_search('^10.[0-9]+')

That seems to have gotten me the result I was looking for.

As for the "default ipv4" not being consistent, I went back and re-read the
article.  Basically, the author said that if you don't set a default route,
then the default.ipv4.address will be empty.  I decided this was not a huge
deal, since I can't think of a situation where I have installed a server
without a default route.  :)

So anyway, thanks again for the help, I do appreciate it.
--John

On Thu, Oct 21, 2021 at 7:43 PM Dick Visser  wrote:

> I don't know about any such unreliability.
> As for determining if the address is in a specific prefix, I would
> definitely use the ipaddr filter:
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters_ipaddr.html
>
> On Fri, 22 Oct 2021 at 00:06, John Petro  wrote:
>
>> Good afternoon.
>>   I have this snippet of code, that sets a proxy variable if the default
>> ipv4 IP address is in 10 net space.  I had read somewhere that using the
>> ansible_default_ipv4 fact, wasn't always reliable.  So is there a better
>> way to grab the primary IP other than what I did below?
>>
>> - name:  PreTask | Configure proxy
>>   set_fact:
>> _zabbix_proxy: "{{zabbix_http_proxy}}"
>>   when: hostvars[inventory_hostname]['ansible_default_ipv4']['address'] |
>> select('match', '^10.[0-9]+')
>>
>> Thanks for the help!!
>>
>> --John
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CAPAjob_VTLnFFUannftz9cgMbdGj7etHN8TtmA%2B%2B7M7aA7L8qg%40mail.gmail.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwMpKBNdfM1FtH4-FemVx_FW1hNk03uwXeLW%2Bv5esTiGcQ%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPAjob-pyQvn3qhyK0aWtKi0YX7O3bSbJVKd5Cd4P2LHBvZ2_Q%40mail.gmail.com.


Re: [ansible-project] Determining the primary IP address

2021-10-21 Thread John Petro
I hadn't heard about any inconsistencies either, which is why I figured I'd
ask here.  I thought about the ipaddr filter, but you need to install a
python module for it to work. (netaddr I think) and I was just trying to
figure it out using the base set of modules, etc.  Thanks for the info
though, I appreciate it

--John

On Thu, Oct 21, 2021, 7:43 PM Dick Visser  wrote:

> I don't know about any such unreliability.
> As for determining if the address is in a specific prefix, I would
> definitely use the ipaddr filter:
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters_ipaddr.html
>
> On Fri, 22 Oct 2021 at 00:06, John Petro  wrote:
>
>> Good afternoon.
>>   I have this snippet of code, that sets a proxy variable if the default
>> ipv4 IP address is in 10 net space.  I had read somewhere that using the
>> ansible_default_ipv4 fact, wasn't always reliable.  So is there a better
>> way to grab the primary IP other than what I did below?
>>
>> - name:  PreTask | Configure proxy
>>   set_fact:
>> _zabbix_proxy: "{{zabbix_http_proxy}}"
>>   when: hostvars[inventory_hostname]['ansible_default_ipv4']['address'] |
>> select('match', '^10.[0-9]+')
>>
>> Thanks for the help!!
>>
>> --John
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CAPAjob_VTLnFFUannftz9cgMbdGj7etHN8TtmA%2B%2B7M7aA7L8qg%40mail.gmail.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwMpKBNdfM1FtH4-FemVx_FW1hNk03uwXeLW%2Bv5esTiGcQ%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPAjob922AxOR0_mS-G230o33_i6HD9bhPDxxjEN3Sg%2BKtKLzQ%40mail.gmail.com.


Re: [ansible-project] Determining the primary IP address

2021-10-21 Thread Dick Visser
I don't know about any such unreliability.
As for determining if the address is in a specific prefix, I would
definitely use the ipaddr filter:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters_ipaddr.html

On Fri, 22 Oct 2021 at 00:06, John Petro  wrote:

> Good afternoon.
>   I have this snippet of code, that sets a proxy variable if the default
> ipv4 IP address is in 10 net space.  I had read somewhere that using the
> ansible_default_ipv4 fact, wasn't always reliable.  So is there a better
> way to grab the primary IP other than what I did below?
>
> - name:  PreTask | Configure proxy
>   set_fact:
> _zabbix_proxy: "{{zabbix_http_proxy}}"
>   when: hostvars[inventory_hostname]['ansible_default_ipv4']['address'] |
> select('match', '^10.[0-9]+')
>
> Thanks for the help!!
>
> --John
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAPAjob_VTLnFFUannftz9cgMbdGj7etHN8TtmA%2B%2B7M7aA7L8qg%40mail.gmail.com
> 
> .
>
-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwMpKBNdfM1FtH4-FemVx_FW1hNk03uwXeLW%2Bv5esTiGcQ%40mail.gmail.com.


[ansible-project] Determining the primary IP address

2021-10-21 Thread John Petro
Good afternoon.
  I have this snippet of code, that sets a proxy variable if the default
ipv4 IP address is in 10 net space.  I had read somewhere that using the
ansible_default_ipv4 fact, wasn't always reliable.  So is there a better
way to grab the primary IP other than what I did below?

- name:  PreTask | Configure proxy
  set_fact:
_zabbix_proxy: "{{zabbix_http_proxy}}"
  when: hostvars[inventory_hostname]['ansible_default_ipv4']['address'] |
select('match', '^10.[0-9]+')

Thanks for the help!!

--John

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPAjob_VTLnFFUannftz9cgMbdGj7etHN8TtmA%2B%2B7M7aA7L8qg%40mail.gmail.com.