Skip to content

Commit 6b69a25

Browse files
authored
Merge pull request #406 from litesh1123/terraform_intro_cheatsheet
Terraform intro cheatsheet
2 parents 25f6174 + 5a2b1ae commit 6b69a25

4 files changed

Lines changed: 453 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Ansible Commands, Playbooks, and Cheatsheet 🚀
2+
3+
## Ansible Commands
4+
5+
### Installation
6+
7+
# Install Ansible on Debian/Ubuntu
8+
```sh
9+
sudo apt update
10+
sudo apt install ansible
11+
```
12+
13+
# Install Ansible on CentOS/RHEL
14+
```sh
15+
sudo yum install ansible
16+
```
17+
18+
### Basic Commands
19+
20+
**Check Ansible version**
21+
```sh
22+
ansible --version
23+
```
24+
**Ping test to check connectivity**
25+
```sh
26+
ansible all -m ping
27+
```
28+
29+
**Ad-hoc command example (installing a package)**
30+
```sh
31+
ansible webserver -m yum -a "name=httpd state=latest"
32+
```
33+
34+
### Ansible Playbooks
35+
**Playbook Structure**
36+
```sh
37+
---
38+
- name: Configure Web Servers
39+
hosts: webservers
40+
become: yes
41+
42+
tasks:
43+
- name: Install Apache
44+
yum:
45+
name: httpd
46+
state: present
47+
48+
- name: Start Apache Service
49+
service:
50+
name: httpd
51+
state: started
52+
```
53+
54+
**Example Playbook**
55+
```sh
56+
---
57+
- name: Setup Monitoring
58+
hosts: monitoring
59+
become: yes
60+
61+
tasks:
62+
- name: Install SNMP Service
63+
yum:
64+
name: net-snmp
65+
state: present
66+
67+
- name: Configure SNMP Community
68+
template:
69+
src: snmpd.conf.j2
70+
dest: /etc/snmp/snmpd.conf
71+
notify:
72+
- restart snmpd
73+
74+
handlers:
75+
- name: restart snmpd
76+
service:
77+
name: snmpd
78+
state: restarted
79+
```
80+
81+
### Ansible Cheatsheet
82+
**Common Modules***
83+
>yum: Manages packages on RPM-based systems.
84+
>apt: Manages packages on Debian-based systems.
85+
>file: Manages files and directories.
86+
>copy: Copies files to remote locations.
87+
>service: Manages services on the system.
88+
>template: Manages file templates.
89+
90+
**Inventory File (hosts.ini)**
91+
```ini
92+
[webservers]
93+
webserver1 ansible_host=192.168.1.101
94+
webserver2 ansible_host=192.168.1.102
95+
96+
[monitoring]
97+
monitor1 ansible_host=192.168.1.201
98+
```
99+
100+
**Variables and Templates**
101+
```sh
102+
# Variable example
103+
---
104+
web_servers:
105+
- hostname: webserver1
106+
ip: 192.168.1.101
107+
108+
# Template example
109+
---
110+
- name: Configure Apache
111+
template:
112+
src: httpd.conf.j2
113+
dest: /etc/httpd/conf/httpd.conf
114+
```
115+
116+
**Troubleshooting and Advanced Tips**
117+
>Use -vvv for verbose output to debug.
118+
>Ensure correct YAML syntax in playbooks (ansible-lint for linting).
119+
>Utilize roles for modular and reusable playbook organization.
120+
>Leverage Ansible Galaxy for community-contributed roles.
121+
122+
**Additional Resources**
123+
For comprehensive Ansible documentation and tutorials, visit [Ansible Documentation](https://docs.ansible.com/).
124+
125+
This Markdown file provides an in-depth reference for Ansible commands, playbook structure, common modules, inventory setup, variables, templates, troubleshooting tips, and advanced techniques. Customize examples and details to suit your specific Ansible deployment and management needs.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Setting Up Control Node and Target Nodes Using Ansible 🌐🔧
2+
3+
## Overview
4+
5+
This guide provides step-by-step instructions to set up a control node and two target nodes using Ansible, a powerful automation tool. Ansible simplifies the management and configuration of multiple nodes from a single control node.
6+
7+
## Prerequisites 📋
8+
9+
- Control node and target nodes accessible over SSH
10+
- Ansible installed on the control node
11+
- Basic understanding of Ansible concepts (inventory, playbooks, etc.)
12+
13+
## Step-by-Step Guide 🛠️
14+
15+
### Step 1: Install Ansible on Control Node
16+
17+
1. **Update the package repository**:
18+
19+
```sh
20+
sudo apt update
21+
22+
2. **Install Ansible:**
23+
```sh
24+
sudo apt install ansible
25+
26+
3. **Verify Ansible installation:**
27+
```sh
28+
ansible --version
29+
30+
### Step 2: Configure SSH Access
31+
32+
1. **Generate SSH keys on the control node (if not already done):**
33+
```sh
34+
ssh-keygen
35+
36+
2. **Copy the SSH public key to the target nodes:**
37+
```sh
38+
ssh-copy-id user@target-node1
39+
ssh-copy-id user@target-node2
40+
```
41+
Replace user with your username and target-node1, target-node2 with the respective IP addresses or hostnames of your target nodes.
42+
43+
3. **Verify SSH connectivity to target nodes:**
44+
```sh
45+
ssh user@target-node1
46+
ssh user@target-node2
47+
48+
### Step 3: Configure Ansible Inventory
49+
50+
1. **Create an Ansible inventory file (e.g., hosts.ini) on the control node:**
51+
```ini
52+
[targets]
53+
target-node1 ansible_host=ip_address1
54+
target-node2 ansible_host=ip_address2
55+
56+
[targets:vars]
57+
ansible_user=user
58+
```
59+
Replace ip_address1, ip_address2 with the IP addresses or hostnames of your target nodes, and user with your SSH username.
60+
61+
### Step 4: Write Ansible Playbook
62+
63+
**Create an Ansible playbook (e.g., setup.yml) to configure the target nodes:**
64+
```yaml
65+
---
66+
- hosts: targets
67+
tasks:
68+
- name: Ensure NTP (Network Time Protocol) is installed
69+
package:
70+
name: ntp
71+
state: present
72+
73+
```
74+
Customize the playbook tasks according to your requirements.
75+
76+
### Step 5: Run Ansible Playbook
77+
78+
1. **Execute the Ansible playbook from the control node:**
79+
```sh
80+
ansible-playbook -i hosts.ini setup.yml
81+
82+
2. **Verify configuration on target nodes:**
83+
```sh
84+
ssh user@target-node1
85+
systemctl status ntp
86+
87+
Repeat for target-node2.
88+
89+
### Conclusion 🎉
90+
91+
You have successfully set up a control node and configured two target nodes using Ansible. This setup enables centralized management and automation of tasks across your infrastructure.
92+
93+
94+
95+
96+
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Hosting and Launching a Web Application with Docker on AWS EC2 Instance 🚀
2+
3+
## Overview
4+
5+
This guide provides a step-by-step process to host and launch a web application using Docker on an AWS EC2 instance.
6+
7+
## Prerequisites 📋
8+
9+
- An AWS account
10+
- Basic knowledge of AWS and Docker
11+
- AWS CLI installed and configured
12+
- SSH access to your EC2 instance
13+
14+
## Step-by-Step Guide 🛠️
15+
16+
### Step 1: Launch an EC2 Instance 🚀
17+
18+
1. **Log in to the AWS Management Console**:
19+
![AWS Management Console](https://d1.awsstatic.com/Developer%20Marketing/Cloud%20Computing.4e208de808476c71af24b19e7e152eed.png)
20+
21+
2. **Navigate to the EC2 Dashboard** and click "Launch Instance":
22+
![EC2 Dashboard](https://d2908q01vomqb2.cloudfront.net/6562cd234fbd38b69ab20c3650da0b0d3088bc2b/2021/04/22/1.png)
23+
24+
3. **Choose an Amazon Machine Image (AMI)**: Select the latest Ubuntu AMI.
25+
![Choose AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_ubuntu.png)
26+
27+
4. **Choose an Instance Type**: Select t2.micro (eligible for the free tier).
28+
![Choose Instance Type](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_instance_type.png)
29+
30+
5. **Configure Instance Details**: Keep the default settings.
31+
![Configure Instance Details](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_configure_instance.png)
32+
33+
6. **Add Storage**: Keep the default settings.
34+
![Add Storage](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_add_storage.png)
35+
36+
7. **Add Tags**: Add a tag with Key = `Name` and Value = `Docker-WebApp`.
37+
![Add Tags](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_add_tags.png)
38+
39+
8. **Configure Security Group**:
40+
- Create a new security group.
41+
- Add rules to allow SSH (port 22) and HTTP (port 80).
42+
![Configure Security Group](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_configure_security_group.png)
43+
44+
9. **Review and Launch**: Click "Launch" and create a new key pair or use an existing one. Download the key pair.
45+
![Review and Launch](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_review.png)
46+
47+
### Step 2: Connect to Your EC2 Instance 🔗
48+
49+
1. **Open your terminal** and navigate to the directory containing your key pair file.
50+
51+
2. **Change the permissions of the key pair file**:
52+
53+
```sh
54+
chmod 400 your-key-pair.pem
55+
56+
3. **Connect to your instance:**
57+
```sh
58+
ssh -i "your-key-pair.pem" ubuntu@your-ec2-public-dns
59+
60+
### Step 3: Install Docker on EC2 Instance 🐳
61+
62+
1. **Update the package database:**
63+
```sh
64+
sudo apt-get update
65+
66+
2. **Install Docker:**
67+
```sh
68+
sudo apt-get install -y docker.io
69+
70+
3. **Start Docker and enable it to start on boot:**
71+
```sh
72+
sudo systemctl start docker
73+
sudo systemctl enable docker
74+
75+
4. **Verify Docker installation:"
76+
```sh
77+
docker --version
78+
79+
### Step 4: Set Up Your Web Application 📦
80+
1. **Clone your web application repository (replace the URL with your repository):**
81+
```sh
82+
git clone https://github.com/your-username/your-webapp.git
83+
cd your-webapp
84+
85+
2. **Create a Dockerfile in the root of your project (if not already present):**
86+
```dockerfile
87+
FROM node:14
88+
89+
WORKDIR /app
90+
91+
COPY package*.json ./
92+
93+
RUN npm install
94+
95+
COPY . .
96+
97+
EXPOSE 3000
98+
99+
CMD ["npm", "start"]
100+
```
101+
3. **Build the Docker image:**
102+
```sh
103+
docker build -t your-webapp .
104+
105+
4. **Run the Docker container:**
106+
```sh
107+
docker run -d -p 80:3000 your-webapp
108+
109+
### Step 5: Access Your Web Application 🌐
110+
Open a web browser and navigate to your EC2 instance's public DNS (IPv4) address.
111+
Your web application should be running and accessible on port 80.
112+
113+
### Conclusion 🎉
114+
You have successfully hosted and launched your web application using Docker on an AWS EC2 instance. Your application is now live and accessible via the internet.
115+
116+
117+

0 commit comments

Comments
 (0)