Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 使用profile作为变量的aws cli命令_Amazon Web Services_Ansible_Aws Cli - Fatal编程技术网

Amazon web services 使用profile作为变量的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

目前我正在ansible中使用任务。该任务包括aws cli命令,如下所示:

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]
    
使用后一种方法的优点是,一旦配置,它将在终端会话期间(或直到它被另一个配置文件名替换)保持其值

参考:AWS CLI文档的章节