Hi Michael, and Benno,
Sorry for not replying early, i had a bad flu. at the end i choose to go
with dictionary the way Michael described, and not the array/list, as
dictionaries are more clear in the playbook tasks. e.g item.key vs item.0
I am currently using Ansible 1.4.5 and i hit a problem with dictionaries
if i format the with_items differently see below what worked for me and
what did not work
### does not work , complains about ""undefined variables: 'str object' has
no attribute 'name' ""
> - debug: var= {{ item.name }}
with_items:
- my_pairs
#### works fine
- debug: var= {{ item.name }}
with_items:
- " {{ my_pairs }}"
##### or this also works fine
- debug: var= {{ item.name }}
with_items: my_pairs
Is that a YAML convention issue, or an ansible parsing bug ?
kind regards
Walid
On 19 February 2014 16:01, Michael DeHaan <[email protected]> wrote:
> Sorry, I meant "lookup" plugin.
>
> I mean if you had something like:
>
> my_sysctls:
> one:
> - { key: x, value: y }
> - { key: x2, value: y2 }
> two:
> ...
>
> and wanted to apply all sysctls in one or two.
>
> I would probably just keep seperate lists and iterate over them, and keep
> those configurations with the roles that need them instead.
>
>
>
>
> On Wed, Feb 19, 2014 at 8:00 AM, Michael DeHaan <[email protected]>wrote:
>
>> The dictsort just sorts them and doesn't really change much.
>>
>> It sounds like you have a list of sysctl names and each sysctl name has a
>> lot of settings under it.
>>
>> You could consider flattening everything to one list, and also maybe
>> using the "when" operator to filter which to apply.
>>
>> If you had a hash of lists and wanted to apply the sysctls in multiple
>> hashes, that might require a filter plugin.
>>
>>
>>
>>
>> On Wed, Feb 19, 2014 at 2:42 AM, benno joy <[email protected]> wrote:
>>
>>> Hi Walid,
>>>
>>> Can you try :
>>>
>>> - sysctl: name={{ item[0] }} value= {{ item[1] }}
>>>
>>> with_items: pana_sys_ctl|dictsort
>>>
>>>
>>> Regards,
>>>
>>> Benno
>>>
>>>
>>>
>>>
>>>
>>> On Wed, Feb 19, 2014 at 11:24 AM, Walid <[email protected]> wrote:
>>>
>>>> Hi Michael,
>>>>
>>>> but in this case the key name is not a static, they key is the sysctl
>>>> parameter, would it be possible to use a similar construct to the one in
>>>> the template? my vars for this use case and also some others are 6-10+
>>>> items, each item could be defined easily as follow
>>>>
>>>> vars:
>>>> pana_sys_ctl:
>>>>
>>>> net.ipv4.ip_local_port_range: 32768 610
>>>>
>>>> net.ipv4.tcp_fin_timeout: 30
>>>>
>>>> net.ipv4.tcp_keepalive_time: 1800
>>>> ....
>>>> pana_mounts:
>>>> mnt1:
>>>> red: filer001:/disk1/vol1
>>>> blue:filer002:/disk1/vol3
>>>> ......
>>>>
>>>> if it is possible through some filters or massaging of the dictionary
>>>> that would be great.
>>>>
>>>> kind regards
>>>>
>>>> Walid
>>>>
>>>>
>>>> On 19 February 2014 04:29, Michael DeHaan <[email protected]> wrote:
>>>>
>>>>> The pattern for iterating over a hash is the same regardless of module
>>>>> and would look like:
>>>>>
>>>>> vars:
>>>>> my_pairs:
>>>>> - key: foo
>>>>> value: bar
>>>>> - key: foo2
>>>>> value: bar2
>>>>>
>>>>> tasks:
>>>>> - shell: echo "{{ item.key }} and {{ item.value }}"
>>>>> with_items: my_pairs
>>>>>
>>>>> So, generally applicable to sysctl or anything else.
>>>>>
>>>>> You could also define the list right under "with_items" without the
>>>>> intermediate variable.
>>>>>
>>>>>
>>>>> On Tue, Feb 18, 2014 at 3:55 PM, Walid <[email protected]>wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>>
>>>>>> I have defined under group_vars, something like the following :
>>>>>>
>>>>>>
>>>>>> ---
>>>>>>
>>>>>> dc001_sysctl:
>>>>>>
>>>>>> net.ipv4.ip_local_port_range: 32768 61000
>>>>>>
>>>>>> net.ipv4.tcp_fin_timeout: 30
>>>>>>
>>>>>> net.ipv4.tcp_keepalive_time: 1800
>>>>>>
>>>>>> ...
>>>>>>
>>>>>> ...
>>>>>>
>>>>>> net.ipv4.neigh.default.gc_thresh1: 2048
>>>>>>
>>>>>> net.ipv4.neigh.default.gc_thresh2: 4096
>>>>>>
>>>>>> net.ipv4.neigh.default.gc_thresh3: 8192
>>>>>>
>>>>>>
>>>>>> the template of the /etc/sysctl.conf looks something like the
>>>>>> following:
>>>>>>
>>>>>>
>>>>>>
>>>>>> {% for parameter,value in dc001_sysctl.getenteries() %}
>>>>>>
>>>>>> {{ parameter }}= {{ value }}
>>>>>>
>>>>>> {% endfor %}
>>>>>>
>>>>>>
>>>>>>
>>>>>> my question if I prefer to do this using the sysctl module, what is
>>>>>> the best way to iterate over these dictionary values in a systctl module
>>>>>> task? my reasoning is to protect against some one have changed the sysctl
>>>>>> from the command line without updating the sysctl.conf file or it is in
>>>>>> the
>>>>>> sysctl.file but was not reloaded.
>>>>>>
>>>>>>
>>>>>> kind regards
>>>>>>
>>>>>>
>>>>>> Walid
>>>>>>
>>>>>> --
>>>>>> 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 [email protected].
>>>>>> To post to this group, send email to [email protected]
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>
>>>>>
>>>>> --
>>>>> 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 [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>
>>>> --
>>>> 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 [email protected].
>>>> To post to this group, send email to [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAN4dctoDxmPS%2BymFOrsYVngdHW0r5Wzem8aarsovdjZbhQ8-Ug%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.