我有一个简单的ansible playbook来创建一个AWS-EC2实例。
我在环境变量中有AWS访问密钥和密钥。在我看来,boto
在尝试连接到AWS时会超时吗?
以下是有关主机,playbook,终端错误日志的详细信息。这可能是代理相关的问题吗?我在我的环境中设置了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'
答案 0 :(得分:0)
没关系..错过了两个错误。 Boto套接字超时 - 这是由于我之前提到的代理。第二个 - AWS授权,这是因为我的ansible脚本中缺少参数'profile'。
local_action: ec2 instance_tags="Name=AnsibleTest"
instance_type={{ instance_type}}
image={{ image }}
wait=true
group_id={{group_id}}
**profile=ProfileToWhichMyUserBelongsTo**