Le 20/05/2016 à 13:13, 'Udondan' via Ansible Development a écrit :
> I wanted to calculate the default gateway from a CIDR. The /ipaddr/
> filter has an undocumented gateway/router option but it results in
> unexpected values.
>
> Here is the responsible method
> <
https://github.com/ansible/ansible/blob/7af47a3886d5a2ebdc49f79564d84a336e10ffcb/lib/ansible/plugins/filter/ipaddr.py#L86>:
>
> |
> def_gateway_query(v):
> ifv.size >1:
> ifv.ip !=v.network:
> returnstr(v.ip)+'/'+str(v.prefixlen)
> |
>
> How is this a gateway? It basically returns the given CIDR.
>
> Since this is not documented it's hard to guess what was the intention
> behind this.
>
> I'd like to send a pull request to change this but first wanted ask what
> you think about it. My proposal would be to change the method to:
>
> |
> def_gateway_query(v):
> ifv.size >1:
> returnstr(netaddr.IPNetwork(str(v.ip)+'/'+str(v.prefixlen))[1])
> |
Hi Daniel,
I am not sure replacing something wrong by something equally wrong is
the proper way to do it.
If you can not use ansible_default_ipv4.gateway because you are working
on something that is not covered by gather_facts, then you really should
provide the gateway explicitly.
M
--
Michel Blanc
{ :github => "@leucos", :twitter => "@b9m", :gpg => "0X24B35C22" }