AWS DevOps Engineer Professional DOP-C01 – Question451

If designing a single playbook to run across multiple Linux distributions that have distribution specific commands, what would be the best method to allow a successful run?

A.
Enable fact gathering and use the `when' conditional to match the distribution to the task.
B. This is not possible, a separate playbook for each target Linux distribution is required.
C. Use `ignore_errors: true' in the tasks.
D. Use the `shell' module to write your own checks for each command that is ran.

Correct Answer: A

Explanation:

Explanation:
Ansible provides a method to only run a task when a condition is met using the `when’ declarative. With gather facts enabled, the play has access to the distribution name of the Linux system, thus, tasks can be tailored to a specific distribution and ran only when the condition is met, e.g.: ` – when: ansible_os_family == “Debian”‘.
Reference:
http://docs.ansible.com/ansible/playbooks_conditionals.html