Ansible inventory cannot recognize ec2 instance inside private subnet

155 Views Asked by At

I have a ec2 instance(without public IP) inside a private subnet. I need to do a code build via code pipeline to the above stated ec2 instance. Further, I have created a bastion host inside a public subnet. Both subnets resides in the same VPC. The route tables and the security groups are created to allow access from bastion server to private ec2 instance. The build spec deploy ansible scripts in the build. I have successfully connected to the private ec2 through bastion host using ssh and can connect to internet from both bastion host and private ec2. So far I have tried 2 scenarios. As follows,

Scenario #1

VPC configuration was done to code build using AWS console.

Issue:- Ansible inventory cannot recognize the private ec2 instance inside private subnet.

Error:- "Failed to describe instances: Connect timeout on endpoint URL: "https://ec2.eu-west-2.amazonaws.com/ "

Scenario #2

Deploying build spec inside bastion server.

Issue:- Ansible inventory cannot recognize the private ec2 instance inside private subnet.

Error:- "Failed to describe instances: Connect timeout on endpoint URL: "https://ec2.eu-west-2.amazonaws.com/ "

AWS ec2 ansible dynamic inventory script is as below,

plugin: aws_ec2
regions: 
    - us-west-1
strict: False
filters:
  "tag:Name": smartEc2
  "instance-state-name": running
0

There are 0 best solutions below