Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible global encrypted variable

Tags:

ansible

Suppose I have just one vault file, containing a bunch of variables I want to keep secret. Is there a way to load the file in Ansible just once, and then globally accessible to all roles and all tasks?

Basically I don't like to replicate var_files everywhere, like this:

- hosts: webserver
  var_files: encrypted.yml
  roles: ....

- hosts: dbserver
  var_files: encrypted.yml
  roles: ....  
like image 673
Kan Li Avatar asked Jul 21 '26 10:07

Kan Li


1 Answers

You can use group_vars, which are variable files that load automatically according to the groups a host is a member of. All hosts are members of the all group, so you can put your common variables in group_vars/all.

The group_vars dir can be relative to (with decreasing priority): the playbook, the inventory file or in /etc/ansible.

If you want to separate encrypted and unencrypted common variables, you can use it as a directory as well:

  • group_vars/all/settings.yml for the normal variables
  • group_vars/all/encrypted.yml for the vaulted ones.

If you don't like my choice of filenames, choose your own, it doesn't matter, as long it's under the all group.

like image 182
hkariti Avatar answered Jul 24 '26 04:07

hkariti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!