Ansible Vault Password in variable

2019-09-11 15:30发布

Is there a way to access the vault password as a variable in an Ansible playbook? I am looking for something like this:

---

debug: var=ansible_vault_password

2条回答
家丑人穷心不美
2楼-- · 2019-09-11 15:56

Try to save the password into a different file and use "vars_files" to include the password. Example:

In Password.yml:

ansible_vault_password: redhat

In Playbook.yml:

Host: xyz

vars_files: password.yml

tasks:

   debug:

       var: "{{ ansible_vault_password }}"

Try this and please let me know.

查看更多
Animai°情兽
3楼-- · 2019-09-11 16:03

I ended up solving this by copying the local vault password file to the server. The task to do that looks like that:

- name: setup ansible vault password file
  copy:
    src: /path/to/local/vault_pass
    dest: /root/.vault_pass
    mode: 0600
    owner: root
    group: root

And then the root user will execute the ansible-pull command.

查看更多
登录 后发表回答