![]() Let’s see how blocks can be used with examples.Ĭreate a playbook ~]$ vim playbook8.yml - name: setting up httpd You should also know that block is a directive in Ansible and not a module, hence the block directive and the when directive will be at the same indentation level. If tasks are grouped conditionally, and the conditions is/are true, all the tasks will be executed. ![]() More so, With the true value for the return_content argument, the body of the response of will be returned as content, and output will be captured with the aid of the register directive.įor the second task, the content “verifying content” will be printed by the debug module with the aid of the msg argument, and with the “failed_when” directive, the task will fail when the string, “this content” and “other content” is not in the captured output.īlocks are used to group tasks, specific tasks that are related, and can be very useful with a conditional statement. The uri module will interact with the webserver and fetch the page. Let’s use the playbook below as an example, ~]$ vim playbook5.yml - name: Web page fetcher The failed_when directive, from its word, simply means the task should fail when a condition is met or not met. Let’s see how this can be done by using the “ failed_when” directive. In this sense, one can specify a condition for tasks to fail or in other words, you are at liberty to determine what a failure is. Create a playbook ~]$ vim playbook7.yml - name: Install basic packageĪnsible may run a task/command successfully, however may be a failure due to the final result a user desires to get. Now, we are going to write a playbook, and we will intentionally make an error by making the name argument of autofs containing “ autos“.ġ. If we were to install the httpd package and the autofs package using a playbook, the name argument will consist of the “ httpd” value and the “ autofs” value. Īs usual, let’s understand better with examples. This behavior can also be changed by using the keyword, “ force_handler: yes”. If a task that is supposed to notify a handler fails, the handlers will not be executed. Well, we learnt about handlers in one of our previous lessons, what about handlers? Yes, this is also applicable to handlers, handlers error can be handled by the keyword, “force_handlers:yes”. More so, if it is added to a task, it means all the errors in the task will be ignored. If it is added to a play, it means that all the errors in the tasks associated to a play will be ignored. ![]() This keyword can be added to a play or a task as the case may be. However, this behavior can be changed with the use of a keyword called “ ignore_errors: true“. How Can Error Handling Be Done In AnsibleĪnsible plays and tasks are executed in the order they are defined in a playbook, and by default, if a task fails, the other tasks will not be executed in that order.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |