Ansible is actually configuration management tool. However, we can use it to provision OS on AWS Cloud as well.
For this purpose we can use Controller node . In AWS O.S. can be launched using either of the following method
AWS does not provide any managed node for configuring OS.
So, we have to use ansible code in local host and the connect to AWS server as a client.
In order to use API service we should have automated ansible code & SDK/library. Python supports boto3 which is a library for API.
We can install boto library using pip command.
Next step is to create ansible playbook using ec2 module & provide required parameters as under
Point to note that we need to provide AWS credentials to login to environment .
For this we’ll need to create IAM user & note down Access Key & Secret Access key . We can include access keys sensitive information in a separate variable file & encrypt it using ansible-vault.
Above snippet shows that Ansible use AWS256 standard for Vault which is very secure.
Finally we can run ansible playbook & launch the EC2 instance.
EC2 dashboard before running Playbook
EC2 dashboard after running ansible playbook
Thus using Ansible we can launch EC2 instance in AWS cloud. So thus it can be used to provision OS on AWS cloud.
We can also decommission EC2 instance using Ansible playbook by specifying the instance id and changing the state
This proves that Ansible can also be used to provision OS on AWS apart from configuration management. This will be very useful business case when client wants to provision multiple EC2 instances at the same time.