ansible-vault encrypt_string 'string_to_encrypt' --name 'secret_variable'
这将创建一个加密的字符串,类似于以下内容:
secret_variable: !vault |
$ANSIBLE_VAULT;1.1;AES256
65326430306165336231653666373638333737643332383734353733393266353834346131333963
6635356233333539346564383636616134616464653232310a383933303230613730393961303639
64343739336461336632653530616534303863363965393931663366326265313136613265363962
3065386665646533350a353131613765313239666461643139626363366135353165356434653764
3737
ansible-vault decrypt_string 'encrypted_string'
这将提供解密的字符串,可以在Playbooks和模板中使用,例如:
secret_variable: '{{ decrypted_string_from_vault }}'
或者将其导出到环境变量:
export secret_variable={{ decrypted_string_from_vault }}
参考链接:https://docs.ansible.com/ansible/latest/user_guide/vault.html#id13