Debugging Possible tasks can be almost impossible if the tasks are not your own. Contrary to what the Ansible website says.
No special coding skills required
Ansible requires highly specialized programming skills because it is not YAML or Python, it is a dirty mixture of both.
The idea of โโusing markup languages โโfor programming was previously discussed. XML was very popular in the Java community at a time. XSLT is also a great example.
As Ansible projects grow, complexity grows exponentially as a result. Take, for example, the OpenShift Ansible project, which performs the following task:
- name: Create the master server certificate command: > {{ hostvars[openshift_ca_host]['first_master_client_binary'] }} adm ca create-server-cert {% for named_ca_certificate in openshift.master.named_certificates | default([]) | lib_utils_oo_collect('cafile') %} --certificate-authority {{ named_ca_certificate }} {% endfor %} {% for legacy_ca_certificate in g_master_legacy_ca_result.files | default([]) | lib_utils_oo_collect('path') %} --certificate-authority {{ legacy_ca_certificate }} {% endfor %} --hostnames={{ hostvars[item].openshift.common.all_hostnames | join(',') }} --cert={{ openshift_generated_configs_dir }}/master-{{ hostvars[item].openshift.common.hostname }}/master.server.crt --key={{ openshift_generated_configs_dir }}/master-{{ hostvars[item].openshift.common.hostname }}/master.server.key --expire-days={{ openshift_master_cert_expire_days }} --signer-cert={{ openshift_ca_cert }} --signer-key={{ openshift_ca_key }} --signer-serial={{ openshift_ca_serial }} --overwrite=false when: item != openshift_ca_host with_items: "{{ hostvars | lib_utils_oo_select_keys(groups['oo_masters_to_config']) | lib_utils_oo_collect(attribute='inventory_hostname', filters={'master_certs_missing':True}) }}" delegate_to: "{{ openshift_ca_host }}" run_once: true
I think we can all agree that this is programming in YAML. Not a good idea. This particular fragment may fail with a message like
fatal: [master0]: FAILED! => {"msg": "The conditional check 'item! = openshift_ca_host' failed. The error was: error evaluating the conditional (item! = openshift_ca_host): 'item' not defined \ n \ nAn error occurred in '/ home / user / openshift-ansible / roles / openshift_master_certificates / tasks / main.yml ': line 39, column 3, but may \ n be elsewhere in the file depending on the exact syntax problem. \ n \ n Violation agreement: \ n \ n \ n- name: create master server certificate \ n ^ here \ n "}
If you press such a message, you are doomed. But do we have a debugger? Ok, let's see what happens.
master0] TASK: openshift_master_certificates : Create the master server certificate (debug)> p task.args {u'_raw_params': u"{{ hostvars[openshift_ca_host]['first_master_client_binary'] }} adm ca create-server-cert {% for named_ca_certificate in openshift.master.named_certificates | default([]) | lib_utils_oo_collect('cafile') %} --certificate-authority {{ named_ca_certificate }} {% endfor %} {% for legacy_ca_certificate in g_master_legacy_ca_result.files | default([]) | lib_utils_oo_collect('path') %} --certificate-authority {{ legacy_ca_certificate }} {% endfor %} --hostnames={{ hostvars[item].openshift.common.all_hostnames | join(',') }} --cert={{ openshift_generated_configs_dir }}/master-{{ hostvars[item].openshift.common.hostname }}/master.server.crt --key={{ openshift_generated_configs_dir }}/master-{{ hostvars[item].openshift.common.hostname }}/master.server.key --expire-days={{ openshift_master_cert_expire_days }} --signer-cert={{ openshift_ca_cert }} --signer-key={{ openshift_ca_key }} --signer-serial={{ openshift_ca_serial }} --overwrite=false"} [master0] TASK: openshift_master_certificates : Create the master server certificate (debug)> exit
How does this help? This is not true.
The point here is that it is an incredibly bad idea to use YAML as a programming language. This is a mess. And the symptoms of the mess we create are everywhere.
Some additional facts. Providing a prerequisite phase for Azure of Openshift Ansible takes +50 minutes. The deployment phase takes more than +70 minutes. Everytime! First run or subsequent runs. And there is no way to limit the provision of a single node. This limit problem was part of Ansible in 2012, and it still remains part of Ansible. This fact tells us something.
The point here is that Ansible should be used as intended. For simple tasks without YAML programming. Great for a large number of servers, but should not be used for complex configuration management tasks.
Ansible is not an infrastructure tool (Code IaC).
If you ask how to debug Ansible problems, you use it in such a way that it is not intended for use. Do not use it as an IaC tool.