我正在尝试对我的敏感信息(例如密码等)使用加密。
问题是:如何使用ansible-vault
来加密变量并在剧本中使用它们?
我知道如何加密字符串(如下所示),但我不知道如何在剧本中成功使用它。
原因是:我需要一些东西来“解密”变量,以便 ansible 可以理解。这些在哪里定义?
我努力了:
ansible-vault encrypt_string -- 'db_password'
提示我的地方:
New Vault password:
Confirm New Vault password:
结果:
!vault |
$ANSIBLE_VAULT;1.1;AES256
63653238643164303561353238643934343861356332323038386236633963326232393830363961
6366336230666134383864306136623030643339353166620a633030646334393563633662653736
35646530383762363262333038376339396432373030363536373232393032316364636565663833
6430316563653265660a366537373637346338383165653531646462313762663035343734316134
3736
Encryption successful
定义保险库变量vault_db_password
vault_db_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
34353733663863636564363261373962616630333032326363633661326363643533326239363165
3531393735333535383063373661336333356164653863630a356139333131323935306265623735
35633665633739656337336562306638646339656235313063643363636433653765633830663330
6136653534383461370a363839313065343731613035383731363337373866613534326261333531
3362
正在使用的 Vault 变量:
MYSQL_ROOT_PASSWORD: "{{ vault_db_password }}"
结果:
FAILED! => {"msg": "Attempting to decrypt but no vault secrets found"}