Skip to content

Commit 0c39323

Browse files
committed
ansible changes
1 parent 69b2384 commit 0c39323

File tree

23 files changed

+286
-29
lines changed

23 files changed

+286
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Run playbook
2+
3+
```bash
4+
ansible-playbook --inventory inventory/ansible-clone-private-repo-playbook/hosts ansible-clone-private-repo-playbook.yml
5+
```
6+
7+
8+
## How to find apache is installed or not
9+
10+
```
11+
type -a apache2
12+
```
13+
14+
15+
## SSH to EC2 instance
16+
17+
```
18+
ssh -i /Users/rahulwagh/.ssh/aws_ec2_terraform [email protected]
19+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
- name: Example Ansible playbook for Handlers
3+
hosts: all
4+
become: yes
5+
remote_user: ubuntu
6+
roles:
7+
- clone-private-repo
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[default]
2+
ec2-3-121-202-218.eu-central-1.compute.amazonaws.com ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
## Clone the private repo on remote server
3+
- name: Clone a private Git repository
4+
git:
5+
repo: [email protected]:rahulwagh/jhooq.git
6+
dest: /home/ubuntu/jhooq-repo
7+
accept_hostkey: yes
8+
key_file: /home/ubuntu/.ssh/id_rsa
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
install_apache_flag: false
3+
4+
5+

part-10-ansible-imports-roles/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ type -a apache2
1515
## SSH to EC2 instance
1616

1717
```
18-
ssh -i /Users/rahulwagh/.ssh/aws_ec2_terraform ubuntu@ec2-3-69-241-84.eu-central-1.compute.amazonaws.com
18+
ssh -i /Users/rahulwagh/.ssh/aws_ec2_terraform ubuntu@ec2-3-74-153-166.eu-central-1.compute.amazonaws.com
1919
```
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
[default]
2-
ec2-3-72-2-115.eu-central-1.compute.amazonaws.com ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform
1+
[aws]
2+
ec2-3-74-153-166.eu-central-1.compute.amazonaws.com ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform

part-10-ansible-imports-roles/roles/install-apache/tasks/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
state: latest
77
update_cache: yes
88

9-
- name: Update Lighttpd configuration
9+
- name: Update Apache configuration
1010
lineinfile:
1111
path: /etc/lighttpd/lighttpd.conf
1212
regexp: '^server.port = 80'
13-
line: 'server.port = 9091'
13+
line: 'server.port = 9090'
1414

1515
- name: Start Apache service
1616
become: yes

part-11-ansible-jinja2-template/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ type -a apache2
1515
## SSH to EC2 instance
1616

1717
```
18-
ssh -i /Users/rahulwagh/.ssh/aws_ec2_terraform ubuntu@ec2-18-196-64-247.eu-central-1.compute.amazonaws.com
18+
ssh -i /Users/rahulwagh/.ssh/aws_ec2_terraform ubuntu@ec2-18-196-119-203.eu-central-1.compute.amazonaws.com
1919
```

part-11-ansible-jinja2-template/ansible-jinja2-template-playbook.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
remote_user: ubuntu
66
roles:
77
- install-lighttpd
8-
- install-apache
8+
#- install-apache
99

1010

1111

part-11-ansible-jinja2-template/roles/install-apache/tasks/main.yml

-12
This file was deleted.

part-11-ansible-jinja2-template/roles/install-lighttpd/tasks/main.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
state: latest
77
update_cache: yes
88

9-
#- name: Update Lighttpd configuration
10-
# lineinfile:
11-
# path: /etc/lighttpd/lighttpd.conf
12-
# regexp: '^server.port = 80'
13-
# line: 'server.port = 9091'
14-
159
- name: Generate configuration file
1610
template:
1711
src: myconfig.j2
@@ -20,7 +14,7 @@
2014
group: root
2115
mode: '0644'
2216
vars:
23-
server_port: 80
17+
server_port: 9090
2418

2519
- name: Start lighttpd service
2620
become: yes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Run playbook
2+
3+
```bash
4+
ansible-playbook --inventory inventory/ansible-deployment-strategy/hosts ansible-deployment-strategy.yml
5+
```
6+
7+
8+
## SSH to EC2 instance
9+
10+
```
11+
ssh -i /Users/rahulwagh/.ssh/aws_ec2_terraform [email protected]
12+
```
13+
14+
## Limit on sub-set of server
15+
16+
```bash
17+
ansible-playbook --inventory inventory/ansible-deployment-strategy/hosts ansible-deployment-strategy.yml --limit blue
18+
```
19+
20+
## Deploy on Sub
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
- name: Example Ansible playbook for Handlers
3+
hosts: all
4+
become: yes
5+
remote_user: ubuntu
6+
roles:
7+
- custom-role
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[blue]
2+
# Server-1
3+
52.59.205.47 ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform
4+
# Server-2
5+
18.194.203.12 ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform
6+
7+
[green]
8+
# Server-3
9+
3.75.236.253 ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform
10+
# Server-4
11+
3.123.154.105 ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: installing packages for python env
3+
become: yes
4+
apt:
5+
name:
6+
- python3-pip
7+
update_cache: yes
8+
9+
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Run playbook
2+
3+
```bash
4+
ansible-playbook --inventory inventory/ansible-error-handling-playbook/hosts ansible-error-handling-playbook.yml
5+
```
6+
7+
8+
## How to find apache is installed or not
9+
10+
```
11+
type -a apache2
12+
```
13+
14+
15+
## SSH to EC2 instance
16+
17+
```
18+
ssh -i /Users/rahulwagh/.ssh/aws_ec2_terraform [email protected]
19+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
- name: Example Ansible playbook for Handlers
3+
hosts: all
4+
become: yes
5+
remote_user: ubuntu
6+
roles:
7+
- custom-role
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[default]
2+
18.198.3.146 ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
# 1. ignore_errors - Ignoring the error
3+
- name: index.html copy with ignore_error
4+
template: src=index.html dest=/home/ubuntu
5+
register: copy_result
6+
ignore_errors: true
7+
8+
- name: String Variable from - main_playbook_variable
9+
debug:
10+
var: copy_result
11+
12+
13+
# 2. any_errors_fatal
14+
- name: index.html copy with failed_when
15+
template: src=index.html dest=/home/ubuntu
16+
failed_when:
17+
- '"Could not find or access" not in copy_result.msg'
18+
- copy_result.failed == true
19+
any_errors_fatal: false
20+
#
21+
#
22+
- name: Create a file if it does not exist
23+
command: touch /home/ubuntu/myfile.txt
24+
register: file_created
25+
changed_when: file_created.rc == 0
26+

part-9-ansible-conditionals/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ type -a apache2
1515
## SSH to EC2 instance
1616

1717
```
18-
ssh -i /Users/rahulwagh/.ssh/aws_ec2_terraform ubuntu@ec2-3-76-215-219.eu-central-1.compute.amazonaws.com
18+
ssh -i /Users/rahulwagh/.ssh/aws_ec2_terraform ubuntu@ec2-3-126-91-79.eu-central-1.compute.amazonaws.com
1919
```
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[default]
2-
ec2-3-69-241-84.eu-central-1.compute.amazonaws.com ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform
2+
ec2-3-126-91-79.eu-central-1.compute.amazonaws.com ansible_ssh_private_key_file=/Users/rahulwagh/.ssh/aws_ec2_terraform
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
install_apache_flag: true
2+
install_apache_flag: false
33

44

55

0 commit comments

Comments
 (0)