简体   繁体   English

变量中的Ansible Vault密码

[英]Ansible Vault Password in variable

Is there a way to access the vault password as a variable in an Ansible playbook? 有没有办法在Ansible剧本中作为变量访问库密码? I am looking for something like this: 我正在寻找这样的东西:

---

debug: var=ansible_vault_password

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. 然后root用户将执行ansible-pull命令。

Try to save the password into a different file and use "vars_files" to include the password. 尝试将密码保存到其他文件中,并使用“ vars_files”包含密码。 Example: 例:

In Password.yml: 在Password.yml中:

ansible_vault_password: redhat

In Playbook.yml: 在Playbook.yml中:

Host: xyz

vars_files: password.yml

tasks:

   debug:

       var: "{{ ansible_vault_password }}"

Try this and please let me know. 试试这个,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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