tags lesson completed
This commit is contained in:
59
README.md
59
README.md
@@ -27,6 +27,9 @@ Red Hat Certified Specialist in Ansible Automation (EX407) Preparation Course
|
|||||||
- [Use Conditionals to Control Play Execution Part 2](#use-conditionals-to-control-play-execution-part-2)
|
- [Use Conditionals to Control Play Execution Part 2](#use-conditionals-to-control-play-execution-part-2)
|
||||||
- [Configure Error Handling](#configure-error-handling)
|
- [Configure Error Handling](#configure-error-handling)
|
||||||
- [Demo: Error Handling – Ignore Errors](#demo-error-handling-ignore-errors)
|
- [Demo: Error Handling – Ignore Errors](#demo-error-handling-ignore-errors)
|
||||||
|
- [Demo: Error Handling – Block Groups](#demo-error-handling-block-groups)
|
||||||
|
- [Selectively Run Specific Tasks In Playbooks Using Tags](#selectively-run-specific-tasks-in-playbooks-using-tags)
|
||||||
|
|
||||||
|
|
||||||
## Understanding Core Components of Ansible
|
## Understanding Core Components of Ansible
|
||||||
### Understanding Core Components of Ansible Part 1
|
### Understanding Core Components of Ansible Part 1
|
||||||
@@ -676,4 +679,58 @@ Demonstration of playbook:
|
|||||||
- We're going to `ignore errors` and even if playbook failed it's going to execute
|
- We're going to `ignore errors` and even if playbook failed it's going to execute
|
||||||
- Output will look like this:
|
- Output will look like this:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### Demo: Error Handling – Block Groups
|
||||||
|
Block groups and rescues - like a try and catch.
|
||||||
|
```
|
||||||
|
---
|
||||||
|
- hosts: labservers
|
||||||
|
tasks:
|
||||||
|
- name: get file
|
||||||
|
block:
|
||||||
|
- get_url:
|
||||||
|
url: "http://innaghiyev3c/index.html"
|
||||||
|
dest: "/tmp/index_file"
|
||||||
|
rescue:
|
||||||
|
- debug: msg="The file doesn't exists!"
|
||||||
|
always:
|
||||||
|
- debug: msg="Play done!"
|
||||||
|
```
|
||||||
|
|
||||||
|
- `rescue` - that part of block will run if playbook run failed
|
||||||
|
- `always` - that part of block will run any time. No matter playbook run fails or not.
|
||||||
|
|
||||||
|
Here how rescue block is working:
|
||||||
|

|
||||||
|
|
||||||
|
### Selectively Run Specific Tasks In Playbooks Using Tags
|
||||||
|
How Ansible uses tags
|
||||||
|
- You can have several deployments in your cookbook. Like database and application deployment
|
||||||
|
- By using tags we can deploy only application stage or only database stage
|
||||||
|
|
||||||
|
```
|
||||||
|
---
|
||||||
|
- hosts: web
|
||||||
|
become: yes
|
||||||
|
tasks:
|
||||||
|
- name: deploy app binary
|
||||||
|
copy:
|
||||||
|
src: /home/cloud_user/apps/hello
|
||||||
|
dest: /var/www/html/hello
|
||||||
|
tags:
|
||||||
|
- webdeploy
|
||||||
|
- hosts: db
|
||||||
|
become: yes
|
||||||
|
tasks:
|
||||||
|
- name: deploy db script
|
||||||
|
copy:
|
||||||
|
src: /home/cloud_user/apps/script.sql
|
||||||
|
dest: /opt/deb/scripts/script.sql
|
||||||
|
tags:
|
||||||
|
- dbdeploy
|
||||||
|
```
|
||||||
|
|
||||||
|
- `ansible-playbook tags_playbook.yml` - running playbook without tags
|
||||||
|
- `ansible-playbook tags_playbook.yml --tags webdeploy` - running playbook only for `webdeploy` part
|
||||||
|
- `ansible-playbook tags_playbook.yml --tags dbdeploy` - running playbook only for `dbdeploy` part
|
||||||
|
|||||||
BIN
images/img16.png
Normal file
BIN
images/img16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 424 KiB |
12
playbooks/block_playbook.yml
Normal file
12
playbooks/block_playbook.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
- hosts: labservers
|
||||||
|
tasks:
|
||||||
|
- name: get file
|
||||||
|
block:
|
||||||
|
- get_url:
|
||||||
|
url: "http://innaghiyev2c/index.html"
|
||||||
|
dest: "/tmp/index_file"
|
||||||
|
rescue:
|
||||||
|
- debug: msg="The file doesn't exists!"
|
||||||
|
always:
|
||||||
|
- debug: msg="Play done!"
|
||||||
19
playbooks/tags_playbook.yml
Normal file
19
playbooks/tags_playbook.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
- hosts: web
|
||||||
|
become: yes
|
||||||
|
tasks:
|
||||||
|
- name: deploy app binary
|
||||||
|
copy:
|
||||||
|
src: /home/user/apps/hello
|
||||||
|
dest: /var/www/html/hello
|
||||||
|
tags:
|
||||||
|
- webdeploy
|
||||||
|
- hosts: db
|
||||||
|
become: yes
|
||||||
|
tasks:
|
||||||
|
- name: deploy db script
|
||||||
|
copy:
|
||||||
|
src: /home/user/apps/script.sql
|
||||||
|
dest: /opt/deb/scripts/script.sql
|
||||||
|
tags:
|
||||||
|
- dbdeploy
|
||||||
Reference in New Issue
Block a user