This is useful when we need to provision ec2-instance and configure any thing into it without updating IP in inventory file.
- Install the ansible using pip module
#pip3 install ansible - Install sshpass software using epel release repo
#yum install sshpass - Install boto3 library for using aws API
#pip3 install boto3 --> for using aws_automate1.yml
#pip3 install boto --> for using aws_automate.yml - Create directory using command - #mkdir /etc/ansible
- Put the file "ansible.cfg" into /etc/ansible folder
#mv ansible.cfg /etc/ansible --> clone the repo in root folder - Change directory by #cd /aws
i) Edit only "aws_var.yml" and put all informations there
ii) After modifying the "aws_var.yml" file run any of the playbook i.e., aws_automate.yml or aws_automate1.yml
Now let start -->
Step 1 - Provisioning EC2-Instance on the aws
- m ec2_instance:
-a " Key_name: key_pair name
instance_type: t2.micro
image_id: image id which you want to launch as OS[ ami-xxxxx]
name: "Your OS name"
vpc_subnet_id: subnet-xxxxxx #your subnet id
network:
assign_public_ip: yes
region: region name
state: present
security_group: sg-xxxxxxxxxxxx #your precreated security group
aws_access_key: Your_access_keys #created from using IAM servive of aws
aws_secret_key: your_secret_keys #created from using IAM servive of aws
Step 2 - Retrieving the IP and copying into the inventory file
-m copy
Step 3 - Installing Webserver into this instance
-m package
Step 4 - creating the webpage
-m copy
Step 5 - Starting the httpd services
-m service