It is possible that depending what the remote machine is where you are running an Ansible Playbook you want to run one action or the other.
For instance: depending on which version of CentOS you are using you would either want to use the binary docker or containerd to run docker.
I would go about accomplishing this in the following way:
- name: stat /var/lib/{{ docker_dir_centos7 }}
stat:
path: /var/lib/{{ docker_dir_centos7 }}
register: var_lib_docker
set_fact:
docker_dir: "{{ docker_dir_centos7 }}"
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "6") or
(ansible_facts['distribution'] == "Debian" and ansible_facts['distribution_major_version'] == "7")
- name: stat /var/lib/{{ docker_dir_centos8 }}
stat:
path: /var/lib/{{ docker_dir_centos8 }}
register: var_lib_docker
set_fact:
docker_dir: "{{ docker_dir_centos8 }}"
when: ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8"
After this I can use {{ docker_dir }} in the remaining steps to access docker binary.
For a more detailed reading on this check this out: https://raymii.org/s/tutorials/Ansible_-_Only_if_on_specific_distribution_or_distribution_version.html