I've had a lot of trouble conditionally setting no or different proxies via ENV when using Ansible.
It was just *impossible* to do this on the playbook level as I was originally recommended. The same incomplete advice went to the documentation, and I'll probably never find out if they wanted to cover up a restriction or just didn't get me. Since there's no Rudder support of FreeBSD yet, I am still using Ansible for this env.
I'd been trying to find a good way around this since like 2013 but always looked at it from the angle that doesn't work, trying to do this via different groups dynamically gathered from the domain and with a proper "proxies" data structure, while still making sure it'd not have the proxy var set where you don't need it...
A few weeks ago I finally figured out my workaround!
Here's what I did in the end - just kept it as trivial as possible.
I adjusted pkg.conf using a template that may or may not render a proxy setting plus the curly braces it so much loves.
- Nothing is defined in group_vars/all
- But something could be defined in there too!
- A proxy is defined in group_vars/domain1
- A different proxy can be defined in group_vars/domain2
- The proxy can be overriden in host_vars/hostname1 (even if the host is in domain2)
- The templated file does not render the section unless the variable was defined
Example proxy definition
You can do the same in host_vars/hostname to override that. I think the underscore bit in group_vars/domaion_name_tld was just for needed for group names built from domains? Maybe I have a gathered group for them? I honestly do not remember at all.