diff --git a/roles/python/tasks/main.yaml b/roles/python/tasks/main.yaml index f2b2787c9..7b68766e7 100644 --- a/roles/python/tasks/main.yaml +++ b/roles/python/tasks/main.yaml @@ -38,6 +38,35 @@ changed_when: false +- become: yes + become_user: root + block: + + - name: check sudo '{{ python_command }}' command + command: "'{{ python_command }}' --version" + changed_when: false + + rescue: + + - name: get sudo 'secure_path' + shell: | + cat /etc/sudoers | + awk '($1 == "Defaults" && $2 == "secure_path"){print $NF}' + changed_when: false + register: get_sudo_secure_path + + - name: add '{{ python_executable | dirname }}' to sudo 'secure_path' + lineinfile: + regex: '{{ get_sudo_secure_path.stdout }}' + path: /etc/sudoers + line: 'Defaults secure_path = {{ python_executable | dirname }}:{{ get_sudo_secure_path.stdout }}' + validate: '/usr/sbin/visudo -cf %s' + + - name: check '{{ python_command }}' command + command: "'{{ python_command }}' --version" + changed_when: false + + - block: - name: check '{{ pip_command }}' command