繁体   English   中英

在 ansible 中使用循环安装 package

[英]installing package using loop in ansible

我需要使用 with_items 循环在 Ansible 中安装 apache2、sqlite3 和 git。 我正在尝试使用下面的代码,但似乎什么也没发生。

---
- hosts: all
  sudo: yes
  name: install apache2, sqlite3, git on remote server
  tasks:
  - name: Install list of packages
    action: apt pkg={{item}} state=installed
    with_items:
      - apache2
      - sqlite3
      - git

你必须将变量放在双引号内......试试这个代码它会工作:

---
- name: install apache2, sqlite3, git on remote servers
  hosts: all
  become: true
  tasks:
    - name: Install packages
      package:
        name: "{{item}}"
        state: present
      loop:
        - apache2
        - sqlite3
        - git

尝试

---
- name: install apache2, sqlite3, git on remote servers
  hosts: all
  sudo: true
  tasks:
    - name: Install packages
      package:
        name: {{ item }}
        state: present
      loop:
        - apache2
        - sqlite3
        - git

请参阅package – 通用操作系统 package 管理器

“这个模块实际上为每个系统(apt、yum 等)调用了相关的 package 模块。”

如果您需要 apt 特定属性,请参阅apt – 管理 apt-packages

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM