March 2019
Intermediate to advanced
412 pages
9h 49m
English
It is relatively common in Ansible to search a string for a substring. In particular, the common administrator task of running a command and grepping the output for a particular key piece of data is a reoccurring construct in many playbooks. While it's possible to replicate this with a shell task to execute a command, and pipe the output into grep, and use careful handling of failed_when to catch grep exit codes, a far better strategy is to use a command task, register the output, and then utilize the Ansible provided regex filters in later conditionals.
Let's look at two examples: one using the shell, pipe, grep method, and another using the search test:
- name: check database version shell: neutron-manage current | ...
Read now
Unlock full access