简体   繁体   中英

ansible include_vars undefind issue while using loop

I have playbook, where i'm trying to loop through the include_vars but somehow loop is not working

Below is my playbook and Error.

Any hint or help with be much appreciated.

Playbook:

---
- 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

Error

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

Note

It works while assigning include_vars separately.

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

you use interpollation like varts but your file names are not a vars. juste remove interpolation:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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