Ansible tasks and playbooks can be profiled in order to single out poor performance in runtime.
Profiling execution times is the most common use-case because this can directly affect boot times.
The default Configuration Framework Service (CFS) ansible.cfg
in the cfs-default-ansible-cfg
ConfigMap does not enable this profiling by default, but does include information on the necessary Ansible callbacks.
Alternatively, if editing the default ansible.cfg
file is not desired, then a new Ansible configuration with profiling enabled can be created and used by CFS.
See Configure Ansible for more information.
(ncn-mw#
) Edit the cfs-default-ansible-cfg
ConfigMap.
kubectl edit cm cfs-default-ansible-cfg -n services
Uncomment the indicated line by removing the #
character from the beginning of the line.
#callback_whitelist = cfs_aggregator, timer, profile_tasks, profile_roles
Comment out the indicated line by adding a #
character to the beginning of the line.
callback_whitelist = cfs_aggregator
Save the modified ConfigMap.
After the modified ConfigMap has been saved, all new CFS sessions that are created will have profiling enabled; profiling information will be available in the Ansible logs of their session pods.
Ansible memory profiling is somewhat limited by the constraints of running Ansible inside Kubernetes containers.
The profiling is useful for determining the relative memory consumption of different tasks,
but the exact values will include some slight overhead from the container because of the fact that a separate cgroup
can not be easily created in the container’s read-only file system.
Similarly, the play’s Execution Maximum
will incorrectly show a value of 0
, because the workaround for Ansible’s attempts to write to a read-only file is to direct it to a temporary file.
(ncn-mw#
) Edit the cfs-default-ansible-cfg
ConfigMap.
kubectl edit cm cfs-default-ansible-cfg -n services
Add cgroup_memory_recap
to the callback_whitelist
line that is currently uncommented.
This can be added to the execution time profiling tasks if desired, or it can be added on its own.
callback_whitelist = cfs_aggregator, cgroup_memory_recap
or
callback_whitelist = cfs_aggregator, timer, profile_tasks, profile_roles, cgroup_memory_recap
Add the following section to the configuration.
Note that the value for
max_mem_file
can not point to/sys/fs/cgroup/memory
, because that is read-only in the container and Ansible will try to write to thememory.max_usage_in_bytes
file.
[callback_cgroupmemrecap]
cur_mem_file = /sys/fs/cgroup/memory/memory.usage_in_bytes
max_mem_file = /tmp/memory.max_usage_in_bytes
Save the modified ConfigMap.
After the modified ConfigMap has been saved, all new CFS sessions that are created will have profiling enabled; profiling information will be available in the Ansible logs of their session pods.