--- - name: Run Python version command ansible.builtin.shell: cmd: python --version | grep -Po '\d+\.\d+' register: _temp_python_version changed_when: false check_mode: false - name: Assign version to dynamic variable ansible.builtin.set_fact: "{{ target_var }}": "{{ _temp_python_version.stdout }}"