小编Mat*_*ock的帖子

如何使用with_items让Ansible执行多个命令?

我想使用Ansible 配置UFW以允许从IP地址列表连接到端口80:

tasks:
    - name: Allow port 80 HTTP
      action: shell ufw allow from {{item}} to any 80/tcp
      with_items: allowed_ips
Run Code Online (Sandbox Code Playgroud)

IP地址列表作为哈希存储在YAML文件中,在我的playbook vars/目录中:

---
allowed_ips:
  xxx.xxx.xxx.xxx
  xxx.xxx.xxx.xxx
Run Code Online (Sandbox Code Playgroud)

我正在使用with_items将IP地址拉入命令,但是当Ansible运行playbook时,它会连接IP地址,在每个IP之间插入一个空格:

ufw allow from xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx to any 80/tcp
Run Code Online (Sandbox Code Playgroud)

ufw不接受这种语法,所以我想ufw为每个IP地址运行一次.我怎样才能做到这一点?

shell ansible

1
推荐指数
1
解决办法
3304
查看次数

标签 统计

ansible ×1

shell ×1