amazon ec2 - Unable to create EC2 when subnet is used via Ansible(same works through AWS-CLI) -


i trying create ec2 instance using ansible. if try without subnet(and default security group), works perfect , creates ec2. not want. want create instance using specific 'sg' , using subnet that's existing(defined organization).

same subnet , 'sg' works fine when using aws-cli(and via console too), same profile, same image, same key , same instance type. creates instance under subnet , assigns sg passed in command - perfect!! can rule out access/role related issues here(as cli/console works fine)? if so, else issue can ansible/boto?

aws cli:

aws ec2 run-instances --image-id ami-3d401234 --count 1 --instance-type t2.large --region us-east-1 --key-name mykeynamehere --security-group-ids sg-766b1234 --subnet-id subnet-09871234 --profile myprofilenamehere 

here playbook.

 - name: provision ec2 node     hosts: local     connection: local     gather_facts: false     tags: provisioning     vars:       instance_type: t2.large       image: ami-3d401234       group_id: sg-766b1234       region: us-east-1       keypair: mykeynamehere       vpc_subnet_id: subnet-09871234      tasks:       - name: launch new instance         local_action: ec2 instance_tags="name=myinstance"                       instance_type={{ instance_type}}                       image={{ image }}                       wait=true                       group_id={{ group_id }}                       profile=myprofilenamehere                       region={{ region }}                       vpc_subnet_id={{ vpc_subnet_id }}                       keypair={{ keypair }}         register: ec2 

and here error, not sure why 401 again(got earlier when profile not mentioned in playbook). sure access , secret keys correct because able create default sg.

    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 1186, in get_list     raise self.responseerror(response.status, response.reason, body) boto.exception.ec2responseerror: ec2responseerror: 401 unauthorized <?xml version="1.0" encoding="utf-8"?> <response><errors><error><code>authfailure</code><message>aws not able validate provided access credentials</message></error></errors><requestid>6182f17d-f62e-4d57-b351-3498dc8a53b7</requestid></response> 

and have access key , secret key information in ~/.boto file. aws_access_key_id , aws_secret_access_key. no iam role information, etc.

this missing in boto, aws_security_token. never thought needed passing access , secret keys. guess needed given access part of organization group? added , works now. @hellov making me check differences again comment :-)


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -