- name: initialize mysql connection on ansible controller block: - name: get ansible controller os distribution setup: gather_subset: - distribution - name: install pymysql package: name: "{{ { 'alpine': 'py3-pymysql', 'debian': 'python3-pymysql' }[ansible_distribution | lower] | d('pymysql') }}" delegate_to: localhost