From c7df83a2f3e56c34ca32f54b7c693da205d49d7b Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Thu, 14 Sep 2023 19:44:32 +0700 Subject: [PATCH 1/6] ansible: add handlers --- .../sample_project/roles/ping-google/handlers/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 topics/ansible/projects/sample_project/roles/ping-google/handlers/README.md diff --git a/topics/ansible/projects/sample_project/roles/ping-google/handlers/README.md b/topics/ansible/projects/sample_project/roles/ping-google/handlers/README.md new file mode 100644 index 0000000..8ce3bc6 --- /dev/null +++ b/topics/ansible/projects/sample_project/roles/ping-google/handlers/README.md @@ -0,0 +1,2 @@ +# What is Handlers? +- In Ansible, handlers are a way to define a list of tasks that should be executed only if certain conditions are met, typically triggered by a notify directive in other tasks. Handlers are often used for actions that need to be taken only when specific changes occur during the playbook run, such as restarting services after configuration changes. \ No newline at end of file From eb881c87b4e6b4997a2e501e02558e9a2c729385 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Thu, 14 Sep 2023 19:46:40 +0700 Subject: [PATCH 2/6] ansible: add template --- .../sample_project/roles/ping-google/templates/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 topics/ansible/projects/sample_project/roles/ping-google/templates/README.md diff --git a/topics/ansible/projects/sample_project/roles/ping-google/templates/README.md b/topics/ansible/projects/sample_project/roles/ping-google/templates/README.md new file mode 100644 index 0000000..dbcc117 --- /dev/null +++ b/topics/ansible/projects/sample_project/roles/ping-google/templates/README.md @@ -0,0 +1,3 @@ +# Template? +- In Ansible, templates are used to dynamically generate configuration files by inserting variable values and other dynamic content into a template file. +- Templates are a powerful way to manage configuration files for various services and applications across different hosts. From 957a66051ca77f47e96042338b90f51d41ef38e0 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Thu, 14 Sep 2023 19:48:51 +0700 Subject: [PATCH 3/6] ansible: add structure --- topics/ansible/projects/sample_project/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/topics/ansible/projects/sample_project/README.md b/topics/ansible/projects/sample_project/README.md index a0ad2c7..bf09f9f 100644 --- a/topics/ansible/projects/sample_project/README.md +++ b/topics/ansible/projects/sample_project/README.md @@ -1,2 +1,17 @@ +# Sample project looks like: +``` +my_ansible_project/ +├── roles/ +│ ├── role1/ +│ │ ├── tasks/ +│ │ │ └── main.yml +│ │ ├── handlers/ +│ │ │ └── main.yml +│ │ ├── templates/ +│ │ ├── defaults/ +│ │ └── meta/ +│ ├── role2/...(same as role1/) +``` + # How to run - Execute this command: `ansible-playbook -i inventory.ini main.yml` (tested on WSL2 Ubuntu) From b36a333db63469d5117fc1aff3b63acfc3341a22 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Thu, 14 Sep 2023 19:49:19 +0700 Subject: [PATCH 4/6] ansible: add structure --- topics/ansible/projects/sample_project/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/topics/ansible/projects/sample_project/README.md b/topics/ansible/projects/sample_project/README.md index bf09f9f..efab340 100644 --- a/topics/ansible/projects/sample_project/README.md +++ b/topics/ansible/projects/sample_project/README.md @@ -10,7 +10,13 @@ my_ansible_project/ │ │ ├── templates/ │ │ ├── defaults/ │ │ └── meta/ -│ ├── role2/...(same as role1/) +│ └── role2/ +│ ├── tasks/ +│ ├── handlers/ +│ ├── templates/ +│ ├── defaults/ +│ └── meta/ +├── main.yml (your main playbook file) ``` # How to run From 86f238ad82ba349befd59de207cabfff42486c31 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Thu, 14 Sep 2023 19:51:13 +0700 Subject: [PATCH 5/6] ansible: add second role - uptime --- topics/ansible/projects/sample_project/main.yml | 3 +++ .../projects/sample_project/roles/check_up_time/tasks/main.yml | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 topics/ansible/projects/sample_project/roles/check_up_time/tasks/main.yml diff --git a/topics/ansible/projects/sample_project/main.yml b/topics/ansible/projects/sample_project/main.yml index a8cc2a9..95fa339 100644 --- a/topics/ansible/projects/sample_project/main.yml +++ b/topics/ansible/projects/sample_project/main.yml @@ -5,3 +5,6 @@ - name: Include ping-google import_role: name: ping-google + - name: Include check_up_time + import_role: + name: check_up_time diff --git a/topics/ansible/projects/sample_project/roles/check_up_time/tasks/main.yml b/topics/ansible/projects/sample_project/roles/check_up_time/tasks/main.yml new file mode 100644 index 0000000..9ccb15c --- /dev/null +++ b/topics/ansible/projects/sample_project/roles/check_up_time/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- name: Execute uptime command + command: uptime From a6c1384d3187d0385abfe3af54d071d504a8a649 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Thu, 14 Sep 2023 19:53:41 +0700 Subject: [PATCH 6/6] ansible: add second role - uptime --- topics/ansible/projects/sample_project/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topics/ansible/projects/sample_project/README.md b/topics/ansible/projects/sample_project/README.md index efab340..5d3491d 100644 --- a/topics/ansible/projects/sample_project/README.md +++ b/topics/ansible/projects/sample_project/README.md @@ -20,4 +20,4 @@ my_ansible_project/ ``` # How to run -- Execute this command: `ansible-playbook -i inventory.ini main.yml` (tested on WSL2 Ubuntu) +- Execute this command: `ansible-playbook -i inventory.ini -v main.yml` (tested on WSL2 Ubuntu)