我对我的 Ansible 库存有这样的想法:我只想拥有一个存储值,即一颗种子,它可以生成我的库存中所需的所有密码。
像这样的东西:
---
# I only have this to generate randomly, and vault
inventory_seed: "a strong random string"
# Then all my other password are derived from this seed.
# I feed the salted seed to a filter that creates a password directly sourced from the string I give him.
# will output, say, `wgSqz$@+SU^nw2;I` everytime I invoke ansible for the same inventory_hostname
machine_root_password: "{{ inventory_hostname + inventory_seed + 'root password' | to_strong_password }}"
# same: dp_password will be the same strong password everytime I invoke ansible
db_password: "{{ inventory_seed + 'db password' | to_strong_password }}"
# ... etc. All my inventory-specific passwords (and other keys) are derived from the same seed
Run Code Online (Sandbox Code Playgroud)
这种方法将有助于解决以下问题:
我还会扩展它来生成密钥对、证书等。启动一个新的清单将减少为仅指定一两个变量,而不是数十个。
这是否存在于(综合)Jinja / Ansible 过滤器中?
我知道该lookup( 'password', xxx)方法,但这是不可重现的:如果提供相同的种子,它不会将种子作为输入来输出相同的密码。我也知道这是一个经常被问到的问题,但每次密码都保存在本地,这是我不想要的。
我必须自己实施吗?
您将如何扩展以生成其他合理但必需的数据(X509 证书、密钥对等)
解决方案是使用password_hash它,也可以与盐和种子结合使用。
这里有些例子:
# uses a random salt
# -> output changes on each run
{{ 'rootpassword' | password_hash('sha512') }}
# uses a user defined salt
# -> output always stays the same
{{ 'rootpassword' | password_hash('sha512', 'secretsalt') }}
# creates a random numeric salt by using the inventory_hostname as a seed
# -> output is unique for every host and stays the same on each run
{{ 'rootpassword' | password_hash('sha512', 12345 | random(seed=inventory_hostname) | string) }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
570 次 |
| 最近记录: |