Skip to content

Commit dc295b8

Browse files
authored
Merge pull request #1 from jahangir842/main
Two more directories added: Azure and Github Actions
2 parents 88fdf4a + 17978dd commit dc295b8

1,513 files changed

Lines changed: 269733 additions & 7 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Retrieve Azure Key Vault Secret
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
get-secret:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# Check out the repository
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
# Log in to Azure using service principal (for Azure CLI)
19+
- name: Log in to Azure CLI
20+
uses: azure/login@v2
21+
with:
22+
creds: |
23+
{
24+
"clientId": "${{ secrets.AZURE_CLIENT_ID }}",
25+
"clientSecret": "${{ secrets.AZURE_CLIENT_SECRET }}",
26+
"tenantId": "${{ secrets.AZURE_TENANT_ID }}",
27+
"subscriptionId": "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
28+
}
29+
30+
# Log in to Azure PowerShell
31+
- name: Log in to Azure PowerShell
32+
shell: pwsh
33+
run: |
34+
# Install Azure PowerShell module
35+
Install-Module -Name Az -Force -AllowClobber -Scope CurrentUser
36+
37+
# Authenticate with service principal
38+
$secureClientSecret = ConvertTo-SecureString "${{ secrets.AZURE_CLIENT_SECRET }}" -AsPlainText -Force
39+
$credential = New-Object System.Management.Automation.PSCredential ("${{ secrets.AZURE_CLIENT_ID }}", $secureClientSecret)
40+
Connect-AzAccount -ServicePrincipal -Credential $credential -TenantId "${{ secrets.AZURE_TENANT_ID }}" -SubscriptionId "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
41+
42+
# Verify login
43+
$context = Get-AzContext
44+
if ($context) {
45+
Write-Output "Logged in as: $($context.Account.Id)"
46+
Write-Output "Subscription: $($context.Subscription.Id)"
47+
} else {
48+
Write-Error "Failed to log in to Azure PowerShell"
49+
exit 1
50+
}
51+
52+
# Retrieve Key Vault Secret
53+
- name: Retrieve Key Vault Secret
54+
shell: pwsh
55+
run: |
56+
# Retrieve the secret
57+
$secret = Get-AzKeyVaultSecret -VaultName "akvjagz" -Name "mytestsecret" -AsPlainText
58+
59+
# Set as environment variable for subsequent steps
60+
echo "MY_SECRET=$secret" >> $GITHUB_ENV
61+
62+
# Example: Use the secret
63+
- name: Use the Secret
64+
shell: bash
65+
run: |
66+
echo "Using secret: [REDACTED]"
67+
# Use ${{ env.MY_SECRET }} in your deployment logic

Ansible/README.md

Lines changed: 158 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,158 @@
1-
## Ansible Tasks ##
2-
- Use the sample website present in the GitHub repository, the link for which is mentioned below.
3-
- https://github.com/Sameer-8080/Website-PRT-ORG.git
4-
- Clone this repository in the Ansible master machine to use for the next task.
5-
- Create the Ansible script to install nginx in one of the Slaves and apache2 in the other, and replace the original index.html files for both the machines with the website in the GitHub link that will have been cloned in the previous step.
1+
# 📘 Ansible Automation Repository
2+
3+
## Readword Demo:
4+
5+
- https://github.com/NASTP-ce/llm-arena/tree/main/ansible
6+
7+
8+
9+
This repository contains **infrastructure automation playbooks** and **roles** managed with Ansible.
10+
It follows a best-practice layout where all automation tasks (NFS, Docker, monitoring tools, etc.) live in one place.
11+
12+
---
13+
14+
## Install Ansible and Shell Autocompletion
15+
16+
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
17+
18+
19+
# Autocomplete:
20+
21+
```bash
22+
# Install argcomplete globally (easier)
23+
bashsudo apt install python3-argcomplete
24+
25+
# Then use:
26+
27+
basheval "$(register-python-argcomplete3 ansible)"
28+
eval "$(register-python-argcomplete3 ansible-playbook)"
29+
eval "$(register-python-argcomplete3 ansible-vault)"
30+
eval "$(register-python-argcomplete3 ansible-galaxy)"
31+
eval "$(register-python-argcomplete3 ansible-config)"
32+
```
33+
34+
35+
## 📂 Directory Structure
36+
37+
```
38+
ansible-project/
39+
├── inventories/
40+
│ ├── production/
41+
│ │ └── hosts.ini # Host inventory (server/client groups)
42+
├── roles/
43+
│ ├── nfs_server/ # Role to configure NFS server
44+
│ │ └── tasks/main.yml
45+
│ ├── nfs_client/ # Role to configure NFS clients
46+
│ │ └── tasks/main.yml
47+
│ ├── <future_roles>/ # Add new roles here (e.g., docker, prometheus)
48+
├── playbooks/
49+
│ └── site.yml # Main entry playbook (calls roles)
50+
└── ansible.cfg # Global Ansible configuration
51+
```
52+
53+
### 🔹 Key Components
54+
55+
* **inventories/** → Defines hosts and groups (production, staging, etc.)
56+
* **roles/** → Modular automation units (server/client/software configs)
57+
* **playbooks/** → Playbooks that orchestrate roles on host groups
58+
* **ansible.cfg** → Defaults (inventory, SSH options, etc.)
59+
60+
---
61+
62+
## ▶️ Usage
63+
64+
### 1. Check connectivity
65+
66+
```bash
67+
ansible all -m ping
68+
```
69+
70+
### 2. Run main site playbook
71+
72+
```bash
73+
ansible-playbook playbooks/site.yml
74+
```
75+
76+
### 3. Run playbook for a specific host group
77+
78+
```bash
79+
ansible-playbook playbooks/site.yml --limit nfs_clients
80+
```
81+
82+
### 4. Run a single ad-hoc command
83+
84+
```bash
85+
ansible all -a "uptime"
86+
ansible nfs_server -a "df -h"
87+
```
88+
89+
### 5. Run a role/playbook with tags
90+
91+
```bash
92+
ansible-playbook playbooks/site.yml --tags "nfs"
93+
```
94+
95+
---
96+
97+
## 🔧 Adding New Software (Best Practice)
98+
99+
1. Create a new role:
100+
101+
```bash
102+
ansible-galaxy init roles/<new_role_name>
103+
```
104+
105+
Example: `roles/docker/`
106+
107+
2. Add tasks in `roles/<new_role_name>/tasks/main.yml`
108+
109+
3. Include the role in `playbooks/site.yml`:
110+
111+
```yaml
112+
- name: Install Docker
113+
hosts: all
114+
become: yes
115+
roles:
116+
- docker
117+
```
118+
119+
4. Run:
120+
121+
```bash
122+
ansible-playbook playbooks/site.yml
123+
```
124+
125+
---
126+
127+
## 📝 Frequently Used Commands Cheat Sheet
128+
129+
* **Check syntax before running**
130+
131+
```bash
132+
ansible-playbook playbooks/site.yml --syntax-check
133+
```
134+
135+
* **Dry run (see changes without applying)**
136+
137+
```bash
138+
ansible-playbook playbooks/site.yml --check
139+
```
140+
141+
* **Limit to one host**
142+
143+
```bash
144+
ansible-playbook playbooks/site.yml --limit 192.168.1.12
145+
```
146+
147+
* **Run with more output**
148+
149+
```bash
150+
ansible-playbook playbooks/site.yml -vvv
151+
```
152+
153+
---
154+
155+
✅ With this structure, all your **future software installations** can be added as new roles.
156+
This makes it easy to scale your automation across multiple environments.
157+
158+
---
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[webservers]
2+
3+
server3 ansible_host=192.168.1.4 ansible_user=user3
4+
server5 ansible_host=192.168.1.6 ansible_user=hassan

Ansible/inventories/staging/hosts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[staging]
2+
# Add staging hosts here

Ansible/playbooks/site.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
3+
4+
- hosts: all
5+
become: yes
6+
tasks:
7+
- name: Install VLC media player
8+
apt:
9+
name: vlc
10+
state: present
11+
when: ansible_os_family == 'Debian'
12+
13+
14+

Ansible/playbooks/webservers.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- hosts: webservers
3+
become: yes
4+
tasks:
5+
- name: Ensure nginx is installed
6+
apt:
7+
name: nginx
8+
state: present
9+
when: ansible_os_family == 'Debian'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is an example file for the example_role.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for example_role
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
# tasks file for example_role
3+
- name: Example task
4+
debug:
5+
msg: "This is an example role task."
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Example Jinja2 template
2+
Hello from {{ inventory_hostname }}!

0 commit comments

Comments
 (0)