1

I am having an Ansible role. In this role, I have vars/main.yml file. In the same directory, I would like to have "secret.yml" file containing vault encrypted variables. What would be the syntax for "main.yml" file to pull the role-wide variables from secret.yml?

secret.yml content:

---
var1: value1
var2: value2

I tried:

main.yml content:

---
- name: Pull variables
  include_vars: secret.yml

error:

→ ./test_deploy.sh
ERROR! failed to combine variables, expected dicts but got a 'dict' and a 'AnsibleSequence':
{}
[{"name": "Pull variables", "include_vars": "secret.yml"}]

main.yml content:

---
- include: secret.yml

error:

→ ./test_deploy.sh
ERROR! failed to combine variables, expected dicts but got a 'dict' and a 'AnsibleSequence':
{}
[{"include": "secret.yml"}]

Does the Ansible even allow for such an import?

silvermat
  • 161
  • 1
  • 1
  • 7
  • 6
    You cannot include variables in `vars/main.yml`, you have to actually do this from `tasks/main.yml` => `include_vars: vars/secret.yml` Meanwhile, it is usually a bad idea to include vaults in a role. You should load them from your playbook/inventory and pass them to your role. – Zeitounator Oct 07 '20 at 18:42

0 Answers0