c0dec0dec0de,
@c0dec0dec0de@hachyderm.io avatar

I hate working with Ansible and Jinja. Is there some set of filters that will take a list of dictionaries like this and work without making Ansible loop and do multiple transactions per host?

- ansible.builtin.package:  
 name: "{{ packages | ??? }}"  
 state: present  
 become: true  
 vars:  
 packages:  
- name:  
- gcc  
- gcc-c++  
 version: "13.2.1"  
- name:  
- libxml2  
- libxml2-devel  
 version: "2.10.4-3"  

jborean,
@jborean@fosstodon.org avatar

@c0dec0dec0de You can do something like

  • package:
    name: '{{ item.name }}'
    version: '{{ item.version | default(omit) }}'
    loop: '{{ packages }}'

No need to mess around with jinja2 filters, name can either be a single string or a list of strings, and version can be omitted in any entry you want if you don't want to define it for that loop item.

c0dec0dec0de,
@c0dec0dec0de@hachyderm.io avatar

@jborean there’s no version argument to the package, yum, or dnf modules. I can do this with a loop, though. I was wondering if there was a way to do it without the loop.

c0dec0dec0de,
@c0dec0dec0de@hachyderm.io avatar

@jborean I can also stick the loop on a set_fact and make a union of all the iterations before using that fact as the name argument to package which has some benefits, can be run_once, only one call to the package manager…

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • Durango
  • DreamBathrooms
  • ngwrru68w68
  • modclub
  • khanakhh
  • magazineikmin
  • mdbf
  • Youngstown
  • rosin
  • slotface
  • everett
  • kavyap
  • GTA5RPClips
  • tacticalgear
  • megavids
  • thenastyranch
  • tester
  • cubers
  • osvaldo12
  • InstantRegret
  • cisconetworking
  • normalnudes
  • provamag3
  • anitta
  • ethstaker
  • Leos
  • JUstTest
  • lostlight
  • All magazines