Amazon web services 使用profile作为变量的aws cli命令
目前我正在ansible中使用任务。该任务包括aws cli命令,如下所示:Amazon web services 使用profile作为变量的aws cli命令,amazon-web-services,ansible,aws-cli,Amazon Web Services,Ansible,Aws Cli,目前我正在ansible中使用任务。该任务包括aws cli命令,如下所示: command: aws ec2 describe-instances --region myregion --profile myawsprofile --filters 它在运行时非常有效 ansible-playbook my.yml 现在我的问题是:我有多个aws配置文件,不想在aws cli命令(在任务中)中使用硬代码。 希望对概要文件使用变量,所以无论传递给概要文件的变量是什么,它都将执行任务并运行a
command: aws ec2 describe-instances --region myregion --profile myawsprofile --filters
它在运行时非常有效
ansible-playbook my.yml
现在我的问题是:我有多个aws配置文件,不想在aws cli命令(在任务中)中使用硬代码。
希望对概要文件使用变量,所以无论传递给概要文件的变量是什么,它都将执行任务并运行ansible playbook 请任何人建议如何进行此操作 我在aws cli中查看了环境变量,但没有起到多大作用。使用它会更好
除此之外,您可能还想查看其他100多个模块。如果您真的想使用命令任务而不是ec2_实例任务,那么您可以:
command: aws ec2 describe-instances --region myregion --profile {{ myawsprofile }} --filters
然后运行你的剧本
ansible-playbook my.yml -e "myawsprofile=production"
您有两个选项(将下面的[profile name]
更改为实际值):
- 为每个命令提供
作为命令选项--profile[profile name]
- 或者,设置要用作环境变量的配置文件。在Mac和Linux上使用
或AWS\U配置文件
AWS\U默认配置文件
或者在窗户上$ export AWS_PROFILE=[profile name]
C:\> setx AWS_PROFILE [profile name]