Ah this also works and is a bit shorter:
...

vars:
    apt_defaults: &apt_defaults
      cache_valid_time: 3600
      install_recommends: no
      update_cache: yes

...

  - name: Install server and helper packages
    apt: pkg={{item}}
    args: *apt_defaults
    with_items:
      - ntp
      - curl
      - git
      - patch
      - htop


On Saturday, February 20, 2016 at 5:30:49 PM UTC-5, Yvo wrote:
>
> Your example has a small syntax error, pkg should be nested under args.
>
> This works:
>
> ...
>
> vars:
>     apt_defaults: &apt_defaults
>       cache_valid_time: 3600
>       install_recommends: no
>       update_cache: yes
>
> ...
>
>   - name: Install server and helper packages
>     apt:
>     args:
>       <<: *apt_defaults
>       pkg: '{{item}}'
>     with_items:
>       - ntp
>       - curl
>       - git
>       - patch
>       - htop
>
> I'm going to play around with it, see if I can move the defaults back to 
> group_vars.
>
> On Saturday, February 20, 2016 at 5:14:09 PM UTC-5, Yvo wrote:
>>
>> Brian, thank you for that workaround.
>>
>> Your solution however forces `pkg` as a separate argument on a new line.
>> How would I supply `install_recommends` to that (specific) task? This for 
>> example doesn't work:
>>
>> ...
>>
>> - apt:
>>   <<: *apt_defaults
>>   pkg: "{{item}}"
>>   install_recommends: yes
>>
>> It would be nice if it was possible to simply set defaults for tasks.
>> Something like:
>>
>> defaults:
>>   apt:
>>     cache_valid_time: 3600
>>
>> And then allowing these defaults to be overridden by the actual task.
>> Even better if you could specify these defaults in the group_vars.
>>
>>
>> On Saturday, February 20, 2016 at 11:42:02 AM UTC-5, Brian Coca wrote:
>>>
>>> in both versions you can still solve this by using YAML references
>>>
>>> vars:
>>>   apt_defaults: &apt_defaults
>>> ...
>>>
>>> - apt:
>>>   <<: *apt_defaults
>>>   pkg: "{{item}}"
>>> ...
>>>
>>>
>>> ----------
>>> Brian Coca
>>>
>>

-- 
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/162360a0-8903-4e61-a2c4-3306649c3278%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to