I want to run similar commands on Linux mint and Ubuntu but they have small differences. I found a solution but it makes me rewrite each task twice. Is there a better way to do that?
- name: install the latest version of Ansible
block:
- name: Add Ansible PPA (Ubuntu)
ansible.builtin.apt_repository:
repo: ppa:ansible/ansible
become: true
when: ansible_facts['distribution'] == 'Ubuntu'
- name: Add Ansible PPA (Linux Mint)
ansible.builtin.apt_repository:
repo: ppa:ansible/ansible
codename: focal
become: true
when: ansible_facts['distribution'] == 'Linux Mint' and ansible_distribution_release == 'una'
- name: install Ansible and dependency
apt:
name:
- software-properties-common
- ansible
state: latest
update_cache: yes
become: true