Ansible with AWS

Hi,

Sorry I’m new to ansible and trying to debate whether I should migrate my current framework to ansible. I’m mainly dealing with provisioning AWS stacks using AWS CLI written in bash. This is probably a stupid question but is there a way to check for things already created (such as VPC ID, AMI ID, etc…) without using “shell” (which basically is invoking AWS CLI anyway)?

Thanks,

Stanley

Hi Stanley,

Do you use CloudFormation scripts with AWS CLI?

Regards,
Constantin

I’m considering that approach as well. Right now, I’m using various cloud modules within Ansible to create the stacks: VPC, Security Group, etc… My problem is these are the sequential steps, says 1-10, and it fails/cancels at 5. I want Ansible checks that 1-5 has been completed and it should start executing the remaining steps. I now have to call AWS CLI from within Ansible’s task to find that out and I think that’s not very elegant and hope Ansible has some other better mechanism.

Will CloudFormation solve that issue for me?

Thanks,

Tam

Hi Stanley,

The ansible modules makes sure that if the resource exists in aws with the same name and properties not to recreate it, so it should be pretty much safe and non time consuming to run steps 1 -5, also you have the option “–start-at-task” through which you can tell ansible playbook to start from which task.

One way to check if resources already exist would be define that resource in your playbook, so if you have a pre existing vpc, use the ec2_vpc module in a task with the same properties of your existing vpc and it would ensure that the vpc exists and report back the details of that vpc.

  • Benno