[ansible-devel] Re: data modeling - group_vars and inventory with deeply nested subdirectories - example included

2021-06-14 Thread Sloane Hertel
I find the flattened common-example directory easier to read. It looks like 
the host vars issue is because REGION is defined in a couple places instead 
of CLUSTER_REGION.

It may be worth taking a look at the generator inventory plugin, which was 
added in 2.6. It looks like you're adding the group structure after adding 
the hosts, but you could probably also easily tweak the plugin to only 
generate groups. 
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/generator_inventory.html

On Tuesday, June 8, 2021 at 5:24:43 PM UTC-4 joeyfr...@gmail.com wrote:

> https://github1s.com/jfreeland/ansible-structure makes the structure a 
> bit easier to digest if you're not already a github1s user.
>
> On Tuesday, June 8, 2021 at 2:19:32 PM UTC-7 Joey Freeland wrote:
>
>> I'm very new to using ansible; please forgive my ignorance.
>>
>> I need to manage groups of machines that all look identical in their 
>> "group."  For various reasons I cannot just use an instance template in my 
>> cloud providers and some on-host bootstrap to configure the nodes when they 
>> start.
>>
>> I have managed to get all of my variables to properly include by doing 
>> something like https://github.com/jfreeland/ansible-structure.  Give it 
>> a shot.
>>
>> This is not what other examples tend to look like.  I've spoken with a 
>> couple peers who were surprised this worked and suggested not going this 
>> route.
>>
>> For various reasons I have to use ansible 2.9 for now.  I don't see any 
>> reason in 
>> https://github.com/ansible/ansible/blob/v2.9.22/lib/ansible/inventory/group.py
>>  
>> why I wouldn't be able to do what I'm doing.
>>
>> Is this not 'supported'?
>>
>> Is this an anti-pattern?
>>
>> Can anyone recommend an alternative or more appropriate approach to 
>> deeply nested group variable inheritance with as little repeating yourself 
>> as practical?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/95cc190b-031c-445a-b4e7-5d5c2668ee54n%40googlegroups.com.


[ansible-devel] Re: Retrieve facts from a lookup plugin

2021-08-23 Thread Sloane Hertel
Make sure the vars are documented, since the documentation doubles as the 
arg spec:
DOCUMENTATION = """
...
options:
  option_name:
description: ...
vars:
  - name: my_var
"""
And use self.get_option('option_name') to retrieve the value after setting 
options with self.set_options(var_options=variables, direct=kwargs).
On Monday, August 23, 2021 at 5:23:08 PM UTC-4 jd...@us.ibm.com wrote:

> I partially answered my own question, from what should have been obvious. 
> The variable stack is passed to the lookup plugin.
> self.set_options(var_options=variables, direct=kwargs)
> x = variables['vars']['']
>
> But I am still stuck with a problem. That returns the literal string value 
> that was assigned to the variable, it does not evaluate that value.
> For example, if I have the following in a vars file
> x: 'a value'
> y: "{{ x }}"
>
> variables['vars']['y'] will return "{{ x }}", not the evaluated result "a 
> value".
>
> Is there some other utility function I need to call to force that 
> evaluation?
>
> On Monday, August 23, 2021 at 10:56:23 AM UTC-4 John Day wrote:
>
>> I should add that I tried setting environment variables using 
>> "environment:" in the play, but those do not appear to be set yet in the 
>> process that is running the jinja2 templating.
>>
>> On Monday, August 23, 2021 at 10:51:16 AM UTC-4 John Day wrote:
>>
>>> I am building a lookup plugin to help with identifying AWS resource ids 
>>> from other relevant resource information, e.g. the Name tag.
>>>
>>> My issue is that I need the region, access key id, and secret access key 
>>> to invoke the boto3 functions and I don't really want to pass these as 
>>> arguments to the lookup function on each use.
>>>
>>> I have these set as both variables and facts in my plays. Is there 
>>> something in ansible utilities that I can call to retrieve the variable 
>>> value or fact variable from within the lookup plugin?
>>>
>>> Thanks in advance.
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/55d12cc0-a45c-4b2c-8c18-4ffbad4d5120n%40googlegroups.com.


Re: [ansible-devel] Enhancement idea - passing module args in loop

2023-11-07 Thread Sloane Hertel
You could use module_defaults 
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_module_defaults.html

  - template:
  owner: root
  group: radiusd
  mode: "0640"
module_defaults:
  template: "{{ item }}"
loop:
- { src: clients.conf.j2, dest: /etc/raddb/clients.conf }
- { src: proxy.conf.j2, dest: /etc/raddb/proxy.conf }

Or/additionally arg splatting (which can be unsafe in some cases if 
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#inject-facts-as-vars
 
is True):

  - template:  "{{ item }}"
module_defaults:
  template:
owner: root
group: radiusd
mode: "0640"
loop:
- { src: clients.conf.j2, dest: /etc/raddb/clients.conf }
- { src: proxy.conf.j2, dest: /etc/raddb/proxy.conf }
On Wednesday, November 1, 2023 at 7:08:10 PM UTC-4 or...@nwra.com wrote:

> I'm not sure what you are trying to say. This doesn't work because what I'm
> proposing doesn't exist.
>
> But I'm wondering if it is worth proposing it as an enhancement.
>
> On 10/31/23 13:23, Avinash Jadhav wrote:
> > Please try this one
> > 
> > - template:
> > args_var: item
> > owner: root
> > group: radiusd
> > mode: "0640"
> >   loop:
> > - { src: clients.conf.j2, dest: /etc/raddb/clients.conf }
> > - { src: proxy.conf.j2, dest: /etc/raddb/proxy.conf }
> > 
> > 
> > On Wed, 1 Nov, 2023, 00:50 Orion Poplawski,  > > wrote:
> > 
> > I find myself writing this over and over again:
> > 
> > - template:
> > src: "{{ item.src }}"
> > dest: "{{ item.dest }}"
> > owner: root
> > group: radiusd
> > mode: "0640"
> >   loop:
> > - { src: clients.conf.j2, dest: /etc/raddb/clients.conf }
> > - { src: proxy.conf.j2, dest: /etc/raddb/proxy.conf }
> > 
> > 
> > What about being able to do something like:
> > 
> > - template:
> > args_var: item
> > owner: root
> > group: radiusd
> > mode: "0640"
> >   loop:
> > - { src: clients.conf.j2, dest: /etc/raddb/clients.conf }
> > - { src: proxy.conf.j2, dest: /etc/raddb/proxy.conf }
> > 
> > Not so dramatic with only two parameters, but I have some with 5 or moe.
> > 
> > -- 
> > Orion Poplawski
> > IT Systems Manager 720-772-5637 
> <(720)%20772-5637>
> > NWRA, Boulder/CoRA Office FAX: 303-415-9702 
> <(303)%20415-9702>
> > 3380 Mitchell Lane   or...@nwra.com
> > 
> > Boulder, CO 80301 https://www.nwra.com/
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups
> > "Ansible Development" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to ansible-deve...@googlegroups.com
> > .
> > To view this discussion on the web visit
> > 
> https://groups.google.com/d/msgid/ansible-devel/35765b61-39cc-46e2-aa5c-b3b728a0ddf8%40nwra.com
>  
> <
> https://groups.google.com/d/msgid/ansible-devel/35765b61-39cc-46e2-aa5c-b3b728a0ddf8%40nwra.com
> >.
> > 
>
> -- 
> Orion Poplawski
> IT Systems Manager 720-772-5637 <(720)%20772-5637>
> NWRA, Boulder/CoRA Office FAX: 303-415-9702 <(303)%20415-9702>
> 3380 Mitchell Lane or...@nwra.com
> Boulder, CO 80301 https://www.nwra.com/
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/f371b2e5-5b30-4d2e-bc01-f832dda9720an%40googlegroups.com.