There are several issues than can occur during a playbook run, mainly related to the syntax of
either the playbook or any of the templates it uses, or due to connectivity issues with the
managed hosts (for example, an error in the host name of the managed host in the inventory
file).
Those errors are issued by the ansible-playbook command at execution time.
--syntax-check option, which checks the YAML syntax for the playbook.
$ ansible-playbook play.yml --syntax-check
You can also use the --step option to step through a playbook one task at a time. The
ansibleplaybook --step command interactively prompts for confirmation that you want each
task to run.
$ansible-playbook play.yml --step
The --start-at-task option allows you to start execution of a playbook from a specific task. It
takes as an argument the name of the task at which to start.
$ansible-playbook play.yml --start-at-task="start httpd service"
Using Ansible’s dry run feature enables users to execute a playbook without making changes to
the servers. It uses the built-in check mode to proof a playbook for errors before execution.
This option is very useful when executing complex playbooks that contain commands which
make major changes to servers. Using the dry run feature helps find fatal errors before they
shut down servers and make them unusable.
Use the -C or --check flag with the ansible-playbook command to do a dry run of an Ansible
playbook:
$ansible-playbook test.yml --check
Or
$ansible-playbook test.yml --check
Using the --diff flag with the ansible-playbook command reports what changes were made while
executing the playbook:
$ansible-playbook playbook.yaml --diff
Combining the --check and --diff flags with the ansible-playbook command gives you a more
detailed overview of all the changes made by your playbook:
$ansible-playbook playbook.yaml --check --diff
This produces the same detailed output you get when using the --diff flag, but without actually
executing any of the changes
The output given by a playbook that was run with the ansible-playbook command is a good
starting point for troubleshooting issues related to hosts managed by Ansible.
At the bottom of the output for each play, the PLAY RECAP section displays the number of
tasks executed for each managed host.
The ansible-playbook -v command provides additional debugging information,
with up to four total levels.
$ansible-playbook -v test.yml
By default, Ansible is not configured to log its output to any log file. It provides a built-in
logging infrastructure that can be configured through the log_path parameter in the default
section of the ansible.cfg configuration file, or through the $ANSIBLE_LOG_PATH environment
variable.
If any or both are configured, Ansible stores output from both the ansible and ansible
playbook commands in the log file configured, either through the ansible.cfg configuration file
or the $ANSIBLE_LOG_PATH environment variable.
$cd
$vim ansible.cfg
[defaults]
log_path = /home/student/troubleshoot-playbook/ansible.log
:wq