Amazon ec2 库存中静态组和动态组的混合

Amazon ec2 库存中静态组和动态组的混合,amazon-ec2,ansible,ansible-inventory,Amazon Ec2,Ansible,Ansible Inventory,我正在尝试将静态和动态(EC2)库存结合起来。有两个ec2实例: 可拆卸控制机 基于ami的主机 正在尝试从控制计算机ping'ami'主机。这是我的主机文件: [local] localhost ansible_connection=local [tag_Name_ami] [tag_Name_redhat] [amazon:children] tag_Name_ami tag_Name_redhat 要成功ping'ami'主机,我需要使用两个特定变量: ansible_

我正在尝试将静态和动态(EC2)库存结合起来。有两个ec2实例:

  • 可拆卸控制机
  • 基于ami的主机
正在尝试从控制计算机ping'ami'主机。这是我的主机文件:

[local] 
localhost ansible_connection=local

[tag_Name_ami]

[tag_Name_redhat]

[amazon:children] 
tag_Name_ami 
tag_Name_redhat
要成功ping'ami'主机,我需要使用两个特定变量:

  • ansible_ssh_用户:ec2用户(我的控制机器是ubuntu)
  • ansible\u ssh\u private\u key\u文件:/home/ubuntu/.ssh/klucze.pem
试图通过在group_vars目录中创建文件来实现:

.
├── demo_setup.yml
├── ec2.ini
├── ec2.py
├── group_vars
│   ├── amazon.yml
│   ├── aws-redhats
│   ├── tag_Name_ami.yml
│   └── tag_Name_redhat.yml
├── hosts
├── hosts.bckp
└── host_vars

$ cat group_vars/tag_Name_ami.yml 
ansible_ssh_user: ec2-user
$ cat group_vars/amazon.yml 
ansible_ssh_private_key_file: /home/ubuntu/.ssh/klucze.pem
问题是ansible似乎只“看到”带有ansible\u ssh\u用户的标记\u Name\u ami.yml,而忽略了带有ansible\u ssh\u private\u key\u文件值的我的amazon.yml。一些输出如下:

$ ansible tag_Name_ami -i ec2.py -m ping -vvv
<52.59.246.244> ESTABLISH CONNECTION FOR USER: ec2-user
<52.59.246.244> REMOTE_MODULE ping
<52.59.246.244> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/ubuntu/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 52.59.246.244 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1452256637.43-34398544897068 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1452256637.43-34398544897068 && echo $HOME/.ansible/tmp/ansible-tmp-1452256637.43-34398544897068'
52.59.246.244 | FAILED => SSH Error: Permission denied (publickey).
    while connecting to 52.59.246.244:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

$ ansible amazon -i ec2.py -m ping
No hosts matched
$ 
将我的静态主机文件与Web服务器组一起使用。剧本看起来像:

---
- hosts: amazon 
  remote_user: ec2-user
  tasks:
  - name: Execute ping
    ping:
...
将“amazon”作为主机值放入playbook返回错误:

PLAY [amazon] ***************************************************************** 
skipping: no hosts matched

还尝试使用“-i ec2.py”执行playbook,同样的错误

您可以在ec2主机上循环,并在playbook中设置变量
ansible\u ssh\u private\u key\u文件

- hosts: amazon
  gather_facts: false
  tasks:
    - set_fact:
        ansible_ssh_private_key_file: '/home/ubuntu/.ssh/klucze.pem'
...

谢谢你的回复。这是否意味着“全球”不可能实现这一目标?我想设置一次,然后忘记它,而无需在每个剧本中添加以下内容
PLAY [amazon] ***************************************************************** 
skipping: no hosts matched
- hosts: amazon
  gather_facts: false
  tasks:
    - set_fact:
        ansible_ssh_private_key_file: '/home/ubuntu/.ssh/klucze.pem'
...