【问题标题】:Boto Socket timeout when provisioning EC2 instance using ansible使用 ansible 配置 EC2 实例时的 Boto Socket 超时
【发布时间】:2016-01-23 12:17:57
【问题描述】:

我有一个简单的 ansible playbook 来创建 AWS-EC2 实例。

我在环境变量中有 AWS 访问密钥和密钥。在我看来,boto 在尝试连接到 AWS 时超时?

以下是来自终端的主机、剧本、错误日志的详细信息。这可能是与代理相关的问题吗?我在我的环境中设置了https_proxy

浏览过其他博客和stackoverflow上的问题,但无法解决。

我的 ansible 主机文件有以下内容。

[localhost]
127.0.0.1

--- # Create ec2 instance playbook

- hosts: localhost
  connection: local
  gather_facts: false
  vars_prompt:
    inst_name: "What's the name of the instance?"
  vars:
      keypair: ".pem name here?? <<I already have ec2 instance that i created manually, using same key name here>>"
      instance_type: "t2.large"
      image: "ami-3d409b56"
      group: "securityGroup here"
      region: "us-east-1"
  tasks:
    - name: make one instance
      ec2: image={{ image }}
           instance_type={{ instance_type }}
           instance_tags='{"Name":"{{ inst_name }}"}'
           region={{ region }}
           group={{ group }}
           vpc_subnet_id="subnet-dfb490a8"
           wait=true
      register: ec2_info

    - name: Add instances to host group
      add_host: hostname={{ item.public_ip }} groupname=ec2hosts
      with_items: ec2_info.instances

    - name: Wait for SSH to come up
      wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
      with_items: ec2_info.instances



****Error:****
failed: [localhost] => {"failed": true, "parsed": false}
Traceback (most recent call last):
  File "/var/root/.ansible/tmp/ansible-tmp-1445631523.13-62493682297224/ec2", line 3070, in <module>
    main()
  File "/var/root/.ansible/tmp/ansible-tmp-1445631523.13-62493682297224/ec2", line 1249, in main
    (instance_dict_array, new_instance_ids, changed) = create_instances(module, ec2, vpc)
  File "/var/root/.ansible/tmp/ansible-tmp-1445631523.13-62493682297224/ec2", line 792, in create_instances
    vpc_id = vpc.get_all_subnets(subnet_ids=[vpc_subnet_id])[0].vpc_id
  File "/Library/Python/2.7/site-packages/boto-2.38.0-py2.7.egg/boto/vpc/__init__.py", line 1153, in get_all_subnets
    return self.get_list('DescribeSubnets', params, [('item', Subnet)])
  File "/Library/Python/2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1170, in get_list
    response = self.make_request(action, params, path, verb)
  File "/Library/Python/2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1116, in make_request
    return self._mexe(http_request)
  File "/Library/Python/2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1030, in _mexe
    raise ex
socket.timeout: timed out

添加代理后出现新错误:

failed: [localhost -> 127.0.0.1] => {"failed": true, "parsed": false}
reply: 'HTTP/1.0 200 Connection established\r\n'
send: 'POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 48\r\nUser-Agent: Boto/2.38.0 Python/2.7.10 Darwin/14.5.0\r\nHost: ec2.us-east-1.amazonaws.com\r\nX-Amz-Date: 20151025T132220Z\r\nContent-Type: application/x-www-form-urlencoded; charset=UTF-8\r\nAuthorization: AWS4-HMAC-SHA256 Credential=MyKEYHere/20151025/us-east-1/ec2/aws4_request,SignedHeaders=host;x-amz-date,Signature=someSignature\r\n\r\nAction=DescribeSecurityGroups&Version=2014-10-01'
reply: 'HTTP/1.1 401 Unauthorized\r\n'

【问题讨论】:

  • 我在我的 ansible 任务中添加了以下行,现在得到 401 异常。看起来它现在至少可以与 AWS 对话了?似乎它没有从我的环境变量中获取访问密钥? '环境:http_proxy:user:password@proxy:port' raise self.ResponseError(response.status, response.reason, body) boto.exception.EC2ResponseError: EC2ResponseError: 401 Unauthorized AuthFailureAWS 无法验证提供的访问凭证

标签: ansible boto


【解决方案1】:

没关系.. 克服了这两个错误。 Boto Socket 超时 - 这是由于我之前提到的代理。第二个 - AWS 授权,这是由于我的 ansible 脚本中缺少参数“profile”。

 local_action: ec2 instance_tags="Name=AnsibleTest"
                  instance_type={{ instance_type}}
                  image={{ image }}
                  wait=true
                  group_id={{group_id}}
                  **profile=ProfileToWhichMyUserBelongsTo**

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    相关资源
    最近更新 更多