Amazon ec2 Ansible创建EC2实例失败,EC2:错误:无法识别的参数:

Amazon ec2 Ansible创建EC2实例失败,EC2:错误:无法识别的参数:,amazon-ec2,ansible,ansible-playbook,Amazon Ec2,Ansible,Ansible Playbook,我是Ansible的新手,并跟随Ansible创建安全组和ec2实例。安全组创建成功,但ec2创建ec2实例失败: 错误:无法识别的参数: /home/ec2 user/.ansible/tmp/ansible-tmp-14244 我确实正确地设置了aws凭据和asnsible变量,如下所示 # AWS Credentials export AWS_ACCESS_KEY_ID=xxx export AWS_SECRET_ACCESS_KEY=xxx # EC2 Environment Vari

我是Ansible的新手,并跟随Ansible创建安全组和ec2实例。安全组创建成功,但ec2创建ec2实例失败:

错误:无法识别的参数: /home/ec2 user/.ansible/tmp/ansible-tmp-14244

我确实正确地设置了aws凭据和asnsible变量,如下所示

# AWS Credentials
export AWS_ACCESS_KEY_ID=xxx
export AWS_SECRET_ACCESS_KEY=xxx

# EC2 Environment Variables
export ANSIBLE_HOSTS=/etc/ansible/ec2.py
export EC2_INI_PATH=/etc/ansible/ec2.ini
文件和输出如下所示。对这个问题有什么想法吗?谢谢你的帮助

$ cat group_vars/all
# Variables listed here are applicable to all host groups 
key_name: sobrr-staging.pem
aws_region: cn-north-1
ami_id: ami-9e0c9ea7
instance_type: m1.small

$ cat basic-create.yml
# Basic provisioning example
- name: Create AWS resources
  hosts: localhost
  connection: local
  gather_facts: False
  tasks:
  - name: Create security group
    ec2_group:
      name: my-security-group
      description: "A Security group"
      region: "{{aws_region}}"
      rules:
        - proto: tcp
          type: ssh
          from_port: 22
          to_port: 22
          cidr_ip: 0.0.0.0/0
      rules_egress:
        - proto: all
          type: all
          cidr_ip: 0.0.0.0/0
    register: basic_firewall

  - name: debug basic_firewall
    debug: 'msg="{{ basic_firewall }}"'

  - name: create an EC2 instance
    local_action:
      module: ec2
      key_name: "{{key_name}}"
      region: "{{aws_region}}"
      group_id: "{{basic_firewall.group_id}}"
      instance_type: "{{instance_type}}"
      image: "{{ami_id}}"
      count: 1
      wait: yes
    register: basic_ec2

  - name: debug instance start
    debug: 'msg="{{ basic_ec2 }}"'
输出

ansible-playbook -i /etc/ansible/hosts -vvvv basic-create.yml
/usr/lib64/python2.6/site-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.
  _warn("Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)

PLAY [Create AWS resources] ***************************************************

TASK: [Create security group] *************************************************
<localhost> region=cn-north-1 description=A Security group name=my-security-group
<localhost>
<localhost>
<localhost> u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.15-98406246607462/ec2_group; rm -rf /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.15-98406246607462/ >/dev/null 2>&1']
ok: [localhost] => {"changed": false, "group_id": "sg-63fae101"}

TASK: [debug basic_firewall] **************************************************
ok: [localhost] => {
    "msg": "{'invocation': {'module_name': u'ec2_group', 'module_args': ''}, 'changed': False, 'group_id': 'sg-63fae101'}"
}

TASK: [create an EC2 instance] ************************************************
<127.0.0.1> instance_type=m1.small image=ami-9e0c9ea7 group_id=sg-63fae101 region=cn-north-1 key_name=sobrr-staging.pem
<127.0.0.1>
<127.0.0.1>
<127.0.0.1>
<127.0.0.1> u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/env python /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/ec2 /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/arguments; rm -rf /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/ >/dev/null 2>&1']
failed: [localhost -> 127.0.0.1] => {"failed": true, "parsed": false}
usage: ec2 [-h] [--list] [--host HOST] [--refresh-cache]
ec2: error: unrecognized arguments: /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/arguments


FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/ec2-user/basic-create.retry

localhost                  : ok=2    changed=0    unreachable=0    failed=1
ansible剧本-i/etc/ansible/hosts-vvv basic-create.yml
/usr/lib64/python2.6/site packages/Crypto/Util/number.py:57:PowmInsecureWarning:不使用mpz_powm_sec。您应该使用libgmp>=5重建以避免定时攻击漏洞。
_警告(“不使用mpz_powm_秒。您应该使用libgmp>=5重建以避免定时攻击漏洞。”,PowmInsecureWarning)
播放[创建AWS资源]***************************************************
任务:[创建安全组]*************************************************
region=cn-north-1 description=安全组名称=我的安全组
u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8/usr/bin/python/home/ec2 user/.ansible/tmp/ansible-tmp-1424461765.15-98406246607462/ec2_组;rm-rf/home/ec2 user/.ansible/tmp/ansible-tmp-1424461765.15-98406246607462/>/dev/null 2>&1']
确定:[localhost]=>{“已更改”:false,“组id”:“sg-63fae101”}
任务:[调试基本防火墙]**************************************************
确定:[本地主机]=>{
“msg:“{'invocation':{'module_name':u'ec2_group','module_args':'','changed':False,'group_id':'sg-63fae101'}”
}
任务:[创建EC2实例]************************************************
实例类型=m1.small image=ami-9e0c9ea7组\u id=sg-63fae101区域=cn-north-1键名称=sobrr-staging.pem
u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8/usr/bin/env python/home/ec2 user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/ec2/home/ec2 user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/arguments;rm-rf/home/ec2 user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/>/dev/null 2>&1']
失败:[localhost->127.0.0.1]=>{“失败”:true,“已解析”:false}
用法:ec2[-h][--list][--host][--refresh cache]
ec2:错误:无法识别的参数:/home/ec2 user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/arguments
致命:所有主机都已失败--正在中止
重演********************************************************************
要重试,请使用:--limit@/home/ec2 user/basic-create.retry
localhost:ok=2已更改=0无法访问=0失败=1

Ansible
ec2模块中的
key\u name
参数指的是您在AWS帐户中上载或创建的ssh公钥(如果您想重用以前的密钥)。您可能需要验证它是否与您在AWS帐户中指定的名称匹配

我猜您AWS帐户中的关键字名称是
sobrr staging
,而不是
sobrr staging.pem

尝试使用
sobrr staging
,看看效果如何