mih
mih

Reputation: 1

ansible include vars from folder different that vars folder for roles

In ansible project I have a folder with multiple yaml files with variables. I am fetching these variables to playbook using include_vars module. But now I have to fetch these variables from roles used by playbooks and include_vars module uses vars folder inside role folder so i am unable to fetch variable files from my folder outside the role folder (if the path is relative and the task is inside a role, it will look inside the role’s vars/ subdirectory). Can someone advice how can I fetch vars from folder outside roles when I am using relative path to this folder?

When using include_vars module in role's main task it always inserts path to vars folder in role into my relative path to variable folder

    ├── roles
│   ├── apply_configuration
│   │   ├── handlers
│   │   │   └── main.yml
│   │   └── tasks
│   │       └── main.yml
└── topologies
    └── topo1
        ├── device1
        │   ├── config_vars
        │   │   ├── vars1.yml
        │   │   ├── vars2.yml
        │   │   ├── vars3.yml

fatal: [device1]: FAILED! => {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message": "/home/user1/git/ansible_project/roles/apply_configuration/vars/topologies/topo1/device1/config_vars directory does not exist"}

Upvotes: 0

Views: 513

Answers (1)

mih
mih

Reputation: 1

Actually i figured out workaround with fileglob lookup plugin. I am able to access vars folder and fetch all variables from files:

- name: Include variables
  ansible.builtin.include_vars:
    file: "{{ item }}"
  with_fileglob:
   - /topologies/topo1/device1/config_vars/*

Upvotes: 0

Related Questions