ansible include_vars 使用循环时未定义的问题

ansible include_vars undefind issue while using loop

我有剧本,我正在尝试循环 include_vars 但不知何故 loop 无法正常工作

下面是我的剧本和错误。

非常感谢任何提示或帮助。

剧本:

---
- name: Running AWS EC2 Play ...
  hosts: localhost
  connection: local
  gather_facts: yes

  tasks:
    - include_vars: "{{ item }}"
      loop:
        - "{{ secret_aws.yml }}"
        - "{{ aws_vars.yml }}"
      no_log: true

错误

TASK [include_vars] ********************************************************************************************************************************************************************
task path: /home/aws/aws_work/new_create_awsVM.yml:8
fatal: [localhost]: FAILED! => {
    "msg": "'secret_aws' is undefined"
}

备注

单独分配include_vars时有效。

- include_vars: aws_vars.yml
- include_vars: aws_secerets.yml

你像疣一样使用插值,但你的文件名不是变量。仅删除插值:

---
- name: Running AWS EC2 Play ...
  hosts: localhost
  connection: local
  gather_facts: yes

  tasks:
    - include_vars: "{{ item }}"
      loop:
        - secret_aws.yml
        - aws_vars.yml