如何按顺序安装ansible yum包
How to install ansible yum packages in order
我有:
ignore_errors: false
become: yes
become_method: sudo
yum:
name: ["epel-release", "clamav"]
state: present
update_cache: yes
它抱怨找不到包,但我需要先安装 epel-release 才能安装 clamav,因为它位于 epel 存储库中。有没有办法保证顺序?除了拆分为 2 个节之外还有哪些选项?谢谢
Ansible循环可以像下面这样解决。
ignore_errors: false
become: yes
become_method: sudo
yum:
name: "{{ item }}"
state: present
update_cache: yes
loop:
- "epel-release"
- "clamav"
尽管使用@Haldum 提出的循环应该可以有效解决您的问题,但 yum
module documentation 不鼓励使用它。由于您肯定需要在使用之前添加 epel 存储库,因此我将创建两个任务,您最终可以在第二个任务中安装多个包。
- name: install my things
hosts: my_hostgroup
become: true
vars:
my_packages:
- clamav
# - some other package maybe
tasks:
- name: Install prerequisite epel repo
yum:
name: epel-release
state: present
- name: Install required packages
yum:
name: "{{ my_packages }}"
state: present
我有:
ignore_errors: false
become: yes
become_method: sudo
yum:
name: ["epel-release", "clamav"]
state: present
update_cache: yes
它抱怨找不到包,但我需要先安装 epel-release 才能安装 clamav,因为它位于 epel 存储库中。有没有办法保证顺序?除了拆分为 2 个节之外还有哪些选项?谢谢
Ansible循环可以像下面这样解决。
ignore_errors: false
become: yes
become_method: sudo
yum:
name: "{{ item }}"
state: present
update_cache: yes
loop:
- "epel-release"
- "clamav"
尽管使用@Haldum 提出的循环应该可以有效解决您的问题,但 yum
module documentation 不鼓励使用它。由于您肯定需要在使用之前添加 epel 存储库,因此我将创建两个任务,您最终可以在第二个任务中安装多个包。
- name: install my things
hosts: my_hostgroup
become: true
vars:
my_packages:
- clamav
# - some other package maybe
tasks:
- name: Install prerequisite epel repo
yum:
name: epel-release
state: present
- name: Install required packages
yum:
name: "{{ my_packages }}"
state: present