{"id":25878303,"url":"https://github.com/dhanikaa/ansible-collection","last_synced_at":"2026-05-06T16:02:30.884Z","repository":{"id":279539811,"uuid":"938639479","full_name":"dhanikaa/Ansible-collection","owner":"dhanikaa","description":"\"This repository provides a complete guide to provisioning AWS EC2 instances using Ansible. It covers setting up Ansible, installing necessary dependencies (Boto3, AWS Collection), securing credentials with Ansible Vault, and writing modular, reusable playbooks using roles and variables.","archived":false,"fork":false,"pushed_at":"2025-02-26T05:04:58.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T05:23:44.975Z","etag":null,"topics":["ansible","ansible-collection","ansible-role"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhanikaa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-25T09:15:40.000Z","updated_at":"2025-02-26T05:06:47.000Z","dependencies_parsed_at":"2025-02-26T05:23:47.973Z","dependency_job_id":"c3bfed7c-2466-40ba-8f2a-1c03828d6ea3","html_url":"https://github.com/dhanikaa/Ansible-collection","commit_stats":null,"previous_names":["dhanikaa/ansible-collection"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhanikaa%2FAnsible-collection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhanikaa%2FAnsible-collection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhanikaa%2FAnsible-collection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhanikaa%2FAnsible-collection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhanikaa","download_url":"https://codeload.github.com/dhanikaa/Ansible-collection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241507129,"owners_count":19973746,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-collection","ansible-role"],"created_at":"2025-03-02T12:29:57.929Z","updated_at":"2026-05-06T16:02:30.785Z","avatar_url":"https://github.com/dhanikaa.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ansible Guide for AWS EC2 Instance Provisioning\n\n## Introduction\n\nThis guide provides a step-by-step approach to provisioning an AWS EC2 instance using Ansible. It covers installing necessary dependencies, setting up Ansible Vault for secure credential management, and making the playbook reusable with variables.\n\nThis guide includes:\n✅ Installing dependencies (Boto3 and AWS Collection)  \n✅ Writing an Ansible playbook for EC2 provisioning  \n✅ Using Ansible Vault for credential security  \n✅ Making the playbook reusable with variables  \n✅ Running the playbook to create an EC2 instance  \n\n---\n\n## Installing Dependencies\n\nBefore provisioning AWS resources, install the required dependencies:\n\n```sh\npip install boto3 botocore\nansible-galaxy collection install amazon.aws\n```\n\n- **Boto3**: Python SDK for AWS, required for Ansible’s AWS modules.\n- **Amazon AWS Collection**: Collection of Ansible modules for AWS provisioning.\n\nVerify installation:\n\n```sh\nansible-galaxy collection list | grep amazon.aws\n```\n\n---\n\n## Writing an Ansible Playbook to Create an EC2 Instance\n\n### 1️⃣ Creating the Role for EC2 Instance\n\nFirst, initialize an Ansible role for EC2 provisioning:\n\n```sh\nansible-galaxy role init ec2\n```\n\nInside `ec2/tasks/main.yaml`, add the following task to create an EC2 instance:\n\n```yaml\n#SPDX-License-Identifier: MIT-0\n---\n  - name: start an instance with a public IP address\n    amazon.aws.ec2_instance:\n      name: \"ansible-instance\"\n      instance_type: t3.micro\n      security_group: default\n      region: eu-north-1\n      aws_access_key: \"{{ ec2_access_key }}\"  # From vault as defined\n      aws_secret_key: \"{{ ec2_secret_key }}\"  # From vault as defined\n      network:\n        assign_public_ip: true\n      image_id: ami-016038ae9cc8d9f51\n      tags:\n        Environment: Testing\n```\n\n### 2️⃣ Writing the Playbook to Use the Role\n\nCreate a playbook `ec2-creation-playbook.yaml` to apply the role:\n\n```yaml\n---\n- hosts: localhost\n  connection: local\n  roles:\n    - ec2\n```\n\n---\n\n## Securing AWS Credentials with Ansible Vault\n\nTo store sensitive AWS credentials securely, use Ansible Vault.\n\n### 1️⃣ Creating a Vault Password File\n\nGenerate a strong password and store it:\n\n```sh\nopenssl rand -base64 2048 \u003e vault.pass\n```\n\n### 2️⃣ Storing AWS Credentials Securely\n\nRun the following command to create an encrypted variable file:\n\n```sh\nansible-vault create group_vars/all/pass.yml --vault-password-file vault.pass\n```\n\nInside `pass.yml`, define the credentials:\n\n```yaml\n---\nec2_access_key: \"YOUR_AWS_ACCESS_KEY\"\nec2_secret_key: \"YOUR_AWS_SECRET_KEY\"\n```\n\n### 3️⃣ Running the Playbook with Vault\n\nExecute the playbook while providing the vault password:\n\n```sh\nansible-playbook ec2-creation-playbook.yaml --vault-password-file vault.pass\n```\n\n---\n\n## Making the Playbook Reusable with Variables\n\nInstead of hardcoding values, use variables.\n\n### 1️⃣ Modifying the Task to Use Variables\n\nModify `ec2/tasks/main.yaml` to reference variables:\n\n```yaml\n#SPDX-License-Identifier: MIT-0\n---\n  - name: start an instance with a public IP address\n    amazon.aws.ec2_instance:\n      name: \"ansible-instance\"\n      instance_type: \"{{ type }}\"\n      security_group: default\n      region: eu-north-1\n      aws_access_key: \"{{ ec2_access_key }}\"  # From vault as defined\n      aws_secret_key: \"{{ ec2_secret_key }}\"  # From vault as defined\n      network:\n        assign_public_ip: true\n      image_id: ami-016038ae9cc8d9f51\n      tags:\n        Environment: Testing\n```\n\n### 2️⃣ Creating a Separate Role for Variables\n\nTo store variable defaults, create another role:\n\n```sh\nansible-galaxy role init ec2-variables\n```\n\nModify `ec2-variables/defaults/main.yaml` to define default values:\n\n```yaml\n---\ntype: t3.micro\n```\n\n### 3️⃣ Writing the New Playbook\n\nCreate `ec2-creation-variables-playbook.yaml` to use both roles:\n\n```yaml\n---\n- hosts: localhost\n  connection: local\n  roles:\n    - ec2-variables\n```\n\nRun the playbook with:\n\n```sh\nansible-playbook ec2-creation-variables-playbook.yaml --vault-password-file vault.pass\n```\n\n---\n\n## Conclusion\n\nBy following this guide, you can:\n✅ Install dependencies and set up Ansible for AWS  \n✅ Write an Ansible playbook to create an EC2 instance  \n✅ Secure AWS credentials with Ansible Vault  \n✅ Use variables to make the playbook reusable  \n\nThis approach makes your AWS provisioning scalable, modular, and secure. 🚀","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhanikaa%2Fansible-collection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhanikaa%2Fansible-collection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhanikaa%2Fansible-collection/lists"}