Ansible 可转换列表默认值

Ansible 可转换列表默认值,ansible,Ansible,在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 # Files needing to run as root u+

在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
# 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 }}"
tasks/main.yml

libexec_path: /opt/nagios/libexec
libexec_owner: nagios
libexec_group: www-data
run_as_root:
  - check_dhcp
  - check_icmp
# 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']

既然已经设置好了,为什么不在上面迭代呢?

修复缩进

- file:
    path: "{{ libexec_path }}/{{ item }}"
    owner: root
    group: "{{ libexec_group }}"
    mode: 4775
  with_items: "{{ run_as_root }}"
您会收到一条错误消息,清楚地告诉您,
未定义;
以根用户身份运行
。如果您直接在
下使用

指定列表,则会出现相同的错误。请修复缩进

- file:
    path: "{{ libexec_path }}/{{ item }}"
    owner: root
    group: "{{ libexec_group }}"
    mode: 4775
  with_items: "{{ run_as_root }}"
您会收到一条错误消息,清楚地表明
未定义;
以\u根运行\u
。如果您直接在
下使用\u项
指定列表,则会出现相同的错误