Ansible Automation | How to create EC2 instance using Ansible Playbook in AWS | Ansible Tutorials
HTML-код
- Опубликовано: 10 сен 2024
- www.coachdevop...
Pre-requisites:
Ansible is installed and Boto is also installed on Ubuntu EC2 instance
Make sure you create an IAM role with AmazonEC2FullAccess policy and attach the role to EC2 instance.
Steps to create EC2 instance using Ansible:
Login to EC2 instance using Git bash or iTerm/putty where you installed Ansible. Execute the below command:
Create an Inventory file first
sudo mkdir /etc/ansible
Edit Ansible hosts or inventory file
sudo vi /etc/ansible/hosts
Add the below two lines in the end of the file:
[localhost]
local
cd ~
mkdir playbooks
cd playbooks
Create Ansible playbook
sudo vi create-ec2.yml
(copy the below content in green color)
edit the create-ec2.yml to make sure you update the key, AMI and region code which is red marked below:
now execute the ansible playbook by
ansible-playbook create_ec2.yml
Hello, for me im still getting the error No Handler was ready to Authenticate....
Im trying to start another ec2 and My inventory file consists of my target ec2 instance and [localhost]
My ec2 is Amazon Linux2023 (IMDv2 enabled)
But works fine if i set (IMDv2 optional)
Need to find a way to make it work even with IMDv2
Plz make it mobile friendly
Sure, thanks for the feedback.