From 76dd641cc53f8385207cb292689a29adb0a20f45 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Tue, 17 Dec 2019 16:40:40 +0100 Subject: [PATCH] Ensure sudo can find python3 command Change-Id: I9b2c2459b844b2e22cd09c572874abfe8dad1ff2 --- roles/python/tasks/main.yaml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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