Ansible: iterate over a results return value yum module

前端 未结 2 1911
失恋的感觉
失恋的感觉 2021-01-17 01:12

Problem: I have many nodes that need package updates. Some of the nodes have these packages installed and some do not. The goal is to 1. check if a package is installed us

2条回答
  •  滥情空心
    2021-01-17 02:08

    The ansible.builtin.yum: module already updates only if a package is installed. You can loop over a list of items using the loop: directive, or if it's a short list, declare the variable within the task block and use the yum module's ability to operate over a list. Like the quick and dirty version.

    - name: update a list of packages
      yum:
        name: "{{ packagelist }}"
        state: latest
      vars:
        packagelist:
          - acpid
          - c-ares 
          - automake
    

    Or, even simpler:

    - name: update a list of packages
      yum:
        name:
          - acpid
          - c-ares 
          - automake
        state: latest
    

    Many more examples are available and all the parameters are defined here: Ansible Docs article about yum

提交回复
热议问题