Commit 0c39323 1 parent 69b2384 commit 0c39323 Copy full SHA for 0c39323
File tree 23 files changed +286
-29
lines changed
ansible-clone-private-repo-on-remote-machine
inventory/ansible-clone-private-repo-playbook
part-10-ansible-imports-roles
inventory/ansible-import-roles-playbook
roles/install-apache/tasks
part-11-ansible-jinja2-template
part-12-ansible-deployment-strategy
inventory/ansible-deployment-strategy
part-13-ansible-error-handling
inventory/ansible-error-handling-playbook
part-9-ansible-conditionals
inventory/ansible-conditionals-playbook
23 files changed +286
-29
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
1
+ ---
2
+ install_apache_flag : false
3
+
4
+
5
+
Original file line number Diff line number Diff line change @@ -15,5 +15,5 @@ type -a apache2
15
15
## SSH to EC2 instance
16
16
17
17
```
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
19
19
```
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 6
6
state : latest
7
7
update_cache : yes
8
8
9
- - name : Update Lighttpd configuration
9
+ - name : Update Apache configuration
10
10
lineinfile :
11
11
path : /etc/lighttpd/lighttpd.conf
12
12
regexp : ' ^server.port = 80'
13
- line : ' server.port = 9091 '
13
+ line : ' server.port = 9090 '
14
14
15
15
- name : Start Apache service
16
16
become : yes
Original file line number Diff line number Diff line change @@ -15,5 +15,5 @@ type -a apache2
15
15
## SSH to EC2 instance
16
16
17
17
```
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
19
19
```
Original file line number Diff line number Diff line change 5
5
remote_user : ubuntu
6
6
roles :
7
7
- install-lighttpd
8
- - install-apache
8
+ # - install-apache
9
9
10
10
11
11
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 6
6
state : latest
7
7
update_cache : yes
8
8
9
- # - name: Update Lighttpd configuration
10
- # lineinfile:
11
- # path: /etc/lighttpd/lighttpd.conf
12
- # regexp: '^server.port = 80'
13
- # line: 'server.port = 9091'
14
-
15
9
- name : Generate configuration file
16
10
template :
17
11
src : myconfig.j2
20
14
group : root
21
15
mode : ' 0644'
22
16
vars :
23
- server_port : 80
17
+ server_port : 9090
24
18
25
19
- name : Start lighttpd service
26
20
become : yes
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
1
+ ---
2
+ - name : installing packages for python env
3
+ become : yes
4
+ apt :
5
+ name :
6
+ - python3-pip
7
+ update_cache : yes
8
+
9
+
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
1
+ [default]
2
+ 18.198.3.146 ansible_ssh_private_key_file =/Users/rahulwagh/.ssh/aws_ec2_terraform
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change @@ -15,5 +15,5 @@ type -a apache2
15
15
## SSH to EC2 instance
16
16
17
17
```
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
19
19
```
Original file line number Diff line number Diff line change 1
1
[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 number Diff line number Diff line change 1
1
---
2
- install_apache_flag : true
2
+ install_apache_flag : false
3
3
4
4
5
5
You can’t perform that action at this time.
0 commit comments