amazon.aws.secretsmanager_secret lookup – 查找存储在 AWS Secrets Manager 中的密钥
注意
此查找插件是 amazon.aws 集合(版本 9.0.0)的一部分。
如果您使用的是 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install amazon.aws
。您需要满足其他要求才能使用此查找插件,有关详细信息,请参阅要求。
要在 Playbook 中使用它,请指定:amazon.aws.secretsmanager_secret
。
概要
查找存储在 AWS Secrets Manager 中的密钥,前提是调用者具有读取密钥的适当权限。
查找基于密钥的名称值。
可选参数可以传递到此查找中;version_id 和 version_stage
在 6.0.0 版本之前,此模块被称为
aws_ssm
,用法保持不变。
别名:aws_secret
要求
在执行此查找的本地控制器节点上需要满足以下要求。
python >= 3.6
boto3 >= 1.28.0
botocore >= 1.31.0
术语
参数 |
注释 |
---|---|
要在 AWS Secrets Manager 中查找的密钥的名称。 |
关键字参数
这描述了查找的关键字参数。这些是在以下示例中 key1=value1
、key2=value2
等值:lookup('amazon.aws.secretsmanager_secret', key1=value1, key2=value2, ...)
和 query('amazon.aws.secretsmanager_secret', key1=value1, key2=value2, ...)
参数 |
注释 |
---|---|
AWS 访问密钥 ID。 有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys。 aws_access_key 和 profile 选项是互斥的。 aws_access_key_id 别名已在 5.1.0 版本中添加,以与 AWS botocore SDK 保持一致。 ec2_access_key 别名已弃用,将在 2024-12-01 之后的版本中删除。 配置
|
|
一个布尔值,指示参数是否作为层次结构提供。 选择
|
|
将两个或多个条目组合以形成扩展密钥。 这对于克服 AWS 施加的 4096 个字符的限制很有用。 与 bypath 一起使用时无效。 选择
|
|
一个布尔值,指示密钥是否包含嵌套值。 选择
|
|
如果密钥已标记为删除,则采取的操作。
选择
|
|
如果拒绝访问密钥,则采取的操作。
选择
|
|
如果密钥丢失,则采取的操作。
选择
|
|
用于身份验证的命名 AWS 配置文件。 有关命名配置文件的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html。 profile 选项与 aws_access_key、aws_secret_key 和 security_token 选项互斥。 boto_profile 别名已弃用,将在 2024-12-01 之后的版本中删除。 配置
|
|
要使用的 AWS 区域。 有关更多信息,请参阅 Amazon AWS 文档 http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region。 配置
|
|
AWS 秘密访问密钥。 有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys。 secret_key 和 profile 选项互斥。 aws_secret_access_key 别名在 5.1.0 版本中添加,以与 AWS botocore SDK 保持一致。 ec2_secret_key 别名已弃用,将在 2024-12-01 之后的版本中删除。 配置
|
|
用于临时凭证的 AWS STS 会话令牌。 有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys。 security_token 和 profile 选项互斥。 别名 aws_session_token 和 session_token 在 3.2.0 版本中添加,参数在 6.0.0 版本中从 security_token 重命名为 session_token。 security_token、aws_security_token 和 access_token 别名已弃用,将在 2024-12-01 之后的版本中删除。 配置
|
|
密钥的版本。 |
|
密钥版本的阶段。 |
注释
注意
当关键字和位置参数一起使用时,位置参数必须在关键字参数之前列出:
lookup('amazon.aws.secretsmanager_secret', term1, term2, key1=value1, key2=value2)
和query('amazon.aws.secretsmanager_secret', term1, term2, key1=value1, key2=value2)
注意:对于模块,环境变量和配置文件是从 Ansible “主机” 上下文读取的,而不是从“控制器” 上下文读取的。因此,可能需要将文件显式复制到“主机”。对于查找和连接插件,环境变量和配置文件是从 Ansible “控制器” 上下文读取的,而不是从“主机”上下文读取的。
Ansible 使用的 AWS SDK (boto3) 也可能会从其在 Ansible “主机” 上下文中的配置文件(通常为
~/.aws/credentials
)读取凭据和其他设置(例如区域)的默认值。有关更多信息,请参阅 https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html。
示例
- name: lookup secretsmanager secret in the current region
debug: msg="{{ lookup('amazon.aws.aws_secret', '/path/to/secrets', bypath=true) }}"
- name: Create RDS instance with aws_secret lookup for password param
rds:
command: create
instance_name: app-db
db_engine: MySQL
size: 10
instance_type: db.m1.small
username: dbadmin
password: "{{ lookup('amazon.aws.aws_secret', 'DbSecret') }}"
tags:
Environment: staging
- name: skip if secret does not exist
debug: msg="{{ lookup('amazon.aws.aws_secret', 'secret-not-exist', on_missing='skip')}}"
- name: warn if access to the secret is denied
debug: msg="{{ lookup('amazon.aws.aws_secret', 'secret-denied', on_denied='warn')}}"
- name: lookup secretsmanager secret in the current region using the nested feature
debug: msg="{{ lookup('amazon.aws.aws_secret', 'secrets.environments.production.password', nested=true) }}"
# The secret can be queried using the following syntax: `aws_secret_object_name.key1.key2.key3`.
# If an object is of the form `{"key1":{"key2":{"key3":1}}}` the query would return the value `1`.
- name: lookup secretsmanager secret in a specific region using specified region and aws profile using nested feature
debug: >
msg="{{ lookup('amazon.aws.aws_secret', 'secrets.environments.production.password', region=region, profile=aws_profile,
access_key=aws_access_key, secret_key=aws_secret_key, nested=true) }}"
# The secret can be queried using the following syntax: `aws_secret_object_name.key1.key2.key3`.
# If an object is of the form `{"key1":{"key2":{"key3":1}}}` the query would return the value `1`.
# Region is the AWS region where the AWS secret is stored.
# AWS_profile is the aws profile to use, that has access to the AWS secret.
返回值
键 |
描述 |
---|---|
返回存储在 AWS Secrets Manager 中的密钥的值。 返回: 成功 |