【问题标题】:Ansible List Default [duplicate]Ansible 列表默认值 [重复]
【发布时间】:2017-10-30 11:23:55
【问题描述】:

在 ansible 中是否可以在 defaults/main.yml 文件中有一个列表,我想设置文件组的权限,但我想在我的角色中使用可以被覆盖的默认列表。

defaults/main.yml

libexec_path: /opt/nagios/libexec
libexec_owner: nagios
libexec_group: www-data
run_as_root:
  - check_dhcp
  - check_icmp

tasks/main.yml

# Files needing to run as root u+s
- file:
    path: "{{ libexec_path }}/{{ item }}"
    owner: root
    group: "{{ libexec_group }}"
    mode: 4775
    with_items: "{{ run_as_root }}"

但是我不断收到错误:

失败了! => {"failed": true, "msg": "任务包含一个选项 一个未定义的变量。错误是:“项目”未定义...

我试过设置

strategy: debug

在主 yml 文件和调试器报告中:

u'run_as_root': [u'check_dhcp', u'check_icmp'],

所以它正在设置,那为什么不对其进行迭代呢?

【问题讨论】:

    标签: ansible


    【解决方案1】:

    修正缩进!

    - file:
        path: "{{ libexec_path }}/{{ item }}"
        owner: root
        group: "{{ libexec_group }}"
        mode: 4775
      with_items: "{{ run_as_root }}"
    

    您收到一条错误消息,明确指出 item 未定义; 不是 run_as_root。如果您直接在with_items 下指定列表,您将遇到相同的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 2018-03-08
      • 2016-10-31
      • 1970-01-01
      相关资源
      最近更新 更多