Simple script to install python 3 (with framework) succeeds manually but fails via ansible

I wonder if anyone can help resolve this for me? I’m trying to install python 3 (using already-installed pyenv) on a (Catalina) Mac: the install goes fine if I don’t try to build it with PYTHON_CONFIGURE_OPTS=“–enable-framework”, but if I supply that flag in the environment then it succeeds by hand (via ssh) but fails via ansible (using suzuki-shunsuke.pyenv-module or shell). To rule out as many confounding factors as possible I put the relevant commands into a small bash script: dopy.sh, and then executed it manually (via ssh) and then again via an ansible play. I can’t figure out why it works via ssh but not via ansible. I’m wondering whether Apple’s SIP might be messing with me. But I’m hoping there’s something simple I can do to make it work!

Here’s the script:


#!/opt/brew/bin/bash
export PATH=/opt/brew/bin:$PATH
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
export PYTHON_CONFIGURE_OPTS="--enable-framework"
env
pyenv install 3.9.5

Here’s the output from the manual (successful) run via ssh:

> ./dopy.sh
SHELL=/opt/brew/bin/bash
PYENV_SHELL=bash
RETICULATE_PYTHON=/Users/mike/.pyenv/shims/python3
SSH_AUTH_SOCK=/tmp/ssh-mwUA66C2q3/agent.43946
PWD=/Users/mike
LOGNAME=mike
HOME=/Users/mike
LANG=en_US.UTF-8
TMPDIR=/var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/
LC_TERMINAL=iTerm2
SSH_CONNECTION=192.168.1.19 61806 192.168.1.29 22
TERM=xterm
USER=mike
LC_TERMINAL_VERSION=3.4.15
PYTHON_CONFIGURE_OPTS=--enable-framework
SHLVL=2
SSH_CLIENT=192.168.1.19 61806 22
LC_ALL=en_US.UTF-8
PATH=/Users/mike/.pyenv/shims:/opt/brew/bin:/Users/mike/.pyenv/shims:/Users/mike/.pyenv/shims:/Users/mike/.pyenv/shims:/Users/mike/.pyenv/shims:/Users/mike/.pyenv/shims:/opt/brew/bin:/Users/mike/.pyenv/shims:/Users/mike/.pyenv/shims:/Users/mike/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
SSH_TTY=/dev/ttys000
_=/usr/bin/env
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Installing Python-3.9.5...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.9.5 to /Users/mike/.pyenv/versions/3.9.5

Now here’s the ansible play:

- name: Install python 3 (with shared libaries for reticulate)

shell: /Users/mike/dopy.sh
environment:
PATH: "{{ homebrew_prefix }}/bin:{{ ansible_env.PATH }}"

and here’s the ansible stderr:

> ansible-playbook -i hosts site.yml -l ${host} -e "ansible_become_pass=${password}" -vvv
ansible-playbook [core 2.12.1]

config file = None
configured module search path = ['/Users/mike/src/ansible-module-cran/library']
ansible python module location = /opt/brew/Cellar/ansible/5.1.0/libexec/lib/python3.10/site-packages/ansible
ansible collection location = /Users/mike/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/brew/bin/ansible-playbook
python version = 3.10.1 (main, Dec 17 2021, 16:24:00) [Clang 13.0.0 (clang-1300.0.27.3)]
jinja version = 3.0.3
libyaml = True
No config file found; using defaults
host_list declined parsing /Users/mike/src/setup/hosts as it did not pass its verify_file() method
script declined parsing /Users/mike/src/setup/hosts as it did not pass its verify_file() method
auto declined parsing /Users/mike/src/setup/hosts as it did not pass its verify_file() method
Parsed /Users/mike/src/setup/hosts inventory source with ini plugin
redirecting (type: modules) ansible.builtin.homebrew_tap to community.general.homebrew_tap
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.osx_defaults to community.general.osx_defaults
redirecting (type: modules) ansible.builtin.osx_defaults to community.general.osx_defaults
redirecting (type: modules) ansible.builtin.osx_defaults to community.general.osx_defaults
redirecting (type: modules) ansible.builtin.osx_defaults to community.general.osx_defaults
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.cpanm to community.general.cpanm
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.cpanm to community.general.cpanm
statically imported: /Users/mike/src/setup/roles/av_dev/tasks/resdet.yml
redirecting (type: modules) ansible.builtin.make to community.general.make
redirecting (type: modules) ansible.builtin.make to community.general.make
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.osx_defaults to community.general.osx_defaults
redirecting (type: modules) ansible.builtin.homebrew_tap to community.general.homebrew_tap
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.osx_defaults to community.general.osx_defaults
redirecting (type: modules) ansible.builtin.osx_defaults to community.general.osx_defaults
redirecting (type: modules) ansible.builtin.osx_defaults to community.general.osx_defaults
redirecting (type: modules) ansible.builtin.osx_defaults to community.general.osx_defaults
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
redirecting (type: modules) ansible.builtin.homebrew_cask to community.general.homebrew_cask
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: site.yml **************************************************************************************
5 plays in site.yml

PLAY [macs] *********************************************************************************************

TASK [Gathering Facts] **********************************************************************************
task path: /Users/mike/src/setup/site.yml:4
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f avon '/bin/sh -c '"'"'echo ~mike && sleep 0'"'"''
<avon> (0, b'/Users/mike\n', b'')
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f avon '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /Users/mike/.ansible/tmp `"&& mkdir "` echo /Users/mike/.ansible/tmp/ansible-tmp-1641064199.6377652-24297-82279717315237 `" && echo ansible-tmp-1641064199.6377652-24297-82279717315237="` echo /Users/mike/.ansible/tmp/ansible-tmp-1641064199.6377652-24297-82279717315237 `" ) && sleep 0'"'"''
<avon> (0, b'ansible-tmp-1641064199.6377652-24297-82279717315237=/Users/mike/.ansible/tmp/ansible-tmp-1641064199.6377652-24297-82279717315237\n', b'')
<avon> Attempting python interpreter discovery
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f avon '/bin/sh -c '"'"'echo PLATFORM; uname; echo FOUND; command -v '"'"'"'"'"'"'"'"'python3.10'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.9'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.8'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.5'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python3'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/libexec/platform-python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python'"'"'"'"'"'"'"'"'; echo ENDFOUND && sleep 0'"'"''
<avon> (0, b'PLATFORM\nDarwin\nFOUND\n/usr/bin/python3\n/usr/bin/python2.7\n/usr/bin/python\n/usr/bin/python\nENDFOUND\n', b'')
<avon> Python interpreter discovery fallback (unsupported platform for extended discovery: darwin)
Using module file /opt/brew/Cellar/ansible/5.1.0/libexec/lib/python3.10/site-packages/ansible/modules/setup.py
<avon> PUT /Users/mike/.ansible/tmp/ansible-local-24294thvgz7ob/tmpjm50w6z3 TO /Users/mike/.ansible/tmp/ansible-tmp-1641064199.6377652-24297-82279717315237/AnsiballZ_setup.py
<avon> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f '[avon]'
<avon> (0, b'sftp> put /Users/mike/.ansible/tmp/ansible-local-24294thvgz7ob/tmpjm50w6z3 /Users/mike/.ansible/tmp/ansible-tmp-1641064199.6377652-24297-82279717315237/AnsiballZ_setup.py\n', b'')
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f avon '/bin/sh -c '"'"'chmod u+x /Users/mike/.ansible/tmp/ansible-tmp-1641064199.6377652-24297-82279717315237/ /Users/mike/.ansible/tmp/ansible-tmp-1641064199.6377652-24297-82279717315237/AnsiballZ_setup.py && sleep 0'"'"''
<avon> (0, b'', b'')
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f -tt avon '/bin/sh -c '"'"'/usr/bin/python3 /Users/mike/.ansible/tmp/ansible-tmp-1641064199.6377652-24297-82279717315237/AnsiballZ_setup.py && sleep 0'"'"''
<avon> (0, b'\r\n{"ansible_facts": {"ansible_interfaces": ["awdl0", "bridge0", "en0", "en1", "en2", "fw0", "gif0", "lo0", "p2p0", "stf0", "utun0", "utun1", "utun2", "utun3", "utun4"], "ansible_lo0": {"device": "lo0", "ipv4": [{"address": "127.0.0.1", "netmask": "255.0.0.0", "network": "127.0.0.0", "broadcast": "127.255.255.255"}], "ipv6": [{"address": "::1", "prefix": "128"}, {"address": "fe80::1%lo0", "prefix": "64", "scope": "0x1"}], "type": "loopback", "flags": ["UP", "LOOPBACK", "RUNNING", "MULTICAST"], "macaddress": "unknown", "mtu": "16384", "options": ["PERFORMNUD", "DAD"]}, "ansible_gif0": {"device": "gif0", "ipv4": [], "ipv6": [], "type": "unknown", "flags": ["POINTOPOINT", "MULTICAST"], "macaddress": "unknown", "mtu": "1280"}, "ansible_stf0": {"device": "stf0", "ipv4": [], "ipv6": [], "type": "unknown", "flags": [], "macaddress": "unknown", "mtu": "1280"}, "ansible_en0": {"device": "en0", "ipv4": [{"address": "192.168.1.29", "netmask": "255.255.255.0", "network": "192.168.1.0", "broadcast": "192.168.1.255"}], "ipv6": [{"address": "fe80::8a:a5dc:beaa:bef5%en0", "prefix": "64"}, {"address": "fdd6:5fa2:b6eb:4997:cb1:56ac:81d:8eae", "prefix": "64"}, {"address": "fdd6:5fa2:b6eb:4997:fde1:ebb6:de14:b2c6", "prefix": "64"}, {"address": "fdd6:5fa2:b6eb:4997:e5d4:4028:155a:3dd0", "prefix": "64"}, {"address": "fdd6:5fa2:b6eb:4997:7c54:5ca:5f35:9ae7", "prefix": "64"}], "type": "ether", "flags": ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], "macaddress": "10:dd:b1:98:dd:27", "mtu": "1500", "options": ["PERFORMNUD", "DAD"], "media": "Unknown", "media_select": "autoselect", "media_type": "1000base", "media_options": ["full-duplex", "flow-control"], "status": "active"}, "ansible_en1": {"device": "en1", "ipv4": [], "ipv6": [], "type": "ether", "flags": ["UP", "BROADCAST", "SMART", "SIMPLEX", "MULTICAST"], "macaddress": "88:53:95:2f:94:41", "mtu": "1500", "options": ["PERFORMNUD", "DAD"], "media": "Unknown", "media_select": "autoselect", "media_type": "<unknow", "media_options": [], "status": "inactive"}, "ansible_en2": {"device": "en2", "ipv4": [], "ipv6": [], "type": "ether", "flags": ["UP", "BROADCAST", "SMART", "RUNNING", "PROMISC", "SIMPLEX", "MULTICAST"], "macaddress": "82:0d:54:f1:bc:00", "mtu": "1500", "options": ["TSO4", "TSO6", "CHANNEL_IO"], "media": "Unknown", "media_select": "autoselect", "media_type": "full-duplex", "status": "inactive"}, "ansible_p2p0": {"device": "p2p0", "ipv4": [], "ipv6": [], "type": "ether", "flags": ["BROADCAST", "SIMPLEX", "MULTICAST"], "macaddress": "0a:53:95:2f:94:41", "mtu": "2304", "options": ["CHANNEL_IO"], "media": "Unknown", "media_select": "autoselect", "status": "inactive"}, "ansible_awdl0": {"device": "awdl0", "ipv4": [], "ipv6": [], "type": "ether", "flags": ["UP", "BROADCAST", "PROMISC", "SIMPLEX", "MULTICAST"], "macaddress": "7a:77:4c:db:d7:ca", "mtu": "1484", "options": ["PERFORMNUD", "DAD"], "media": "Unknown", "media_select": "autoselect", "status": "inactive"}, "ansible_fw0": {"device": "fw0", "ipv4": [], "ipv6": [], "type": "unknown", "flags": ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], "macaddress": "unknown", "mtu": "4078", "lladdr": "10:dd:b1:ff:fe:53:c6:f0", "options": ["PERFORMNUD", "DAD"], "media": "Unknown", "media_select": "autoselect", "media_type": "full-duplex", "status": "inactive"}, "ansible_bridge0": {"device": "bridge0", "ipv4": [], "ipv6": [], "type": "ether", "flags": ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], "macaddress": "82:0d:54:f1:bc:00", "mtu": "1500", "options": ["PERFORMNUD", "DAD"], "media": "Unknown", "media_select": "Unknown", "media_type": "unknown type", "status": "inactive"}, "ansible_utun0": {"device": "utun0", "ipv4": [], "ipv6": [{"address": "fe80::2150:2ee7:5a06:582d%utun0", "prefix": "64", "scope": "0xb"}], "type": "unknown", "flags": ["UP", "POINTOPOINT", "RUNNING", "MULTICAST"], "macaddress": "unknown", "mtu": "1380", "options": ["PERFORMNUD", "DAD"]}, "ansible_utun1": {"device": "utun1", "ipv4": [], "ipv6": [{"address": "fe80::f155:9d9a:da95:f07c%utun1", "prefix": "64", "scope": "0xc"}], "type": "unknown", "flags": ["UP", "POINTOPOINT", "RUNNING", "MULTICAST"], "macaddress": "unknown", "mtu": "2000", "options": ["PERFORMNUD", "DAD"]}, "ansible_utun2": {"device": "utun2", "ipv4": [], "ipv6": [{"address": "fe80::db1b:fa86:10a6:5743%utun2", "prefix": "64", "scope": "0xd"}], "type": "unknown", "flags": ["UP", "POINTOPOINT", "RUNNING", "MULTICAST"], "macaddress": "unknown", "mtu": "1380", "options": ["PERFORMNUD", "DAD"]}, "ansible_utun3": {"device": "utun3", "ipv4": [], "ipv6": [{"address": "fe80::d237:9dc2:fd04:a8c5%utun3", "prefix": "64", "scope": "0xe"}], "type": "unknown", "flags": ["UP", "POINTOPOINT", "RUNNING", "MULTICAST"], "macaddress": "unknown", "mtu": "1380", "options": ["PERFORMNUD", "DAD"]}, "ansible_utun4": {"device": "utun4", "ipv4": [], "ipv6": [{"address": "fe80::9724:15e7:a396:906d%utun4", "prefix": "64", "scope": "0xf"}], "type": "unknown", "flags": ["UP", "POINTOPOINT", "RUNNING", "MULTICAST"], "macaddress": "unknown", "mtu": "1380", "options": ["PERFORMNUD", "DAD"]}, "ansible_default_ipv4": {"gateway": "192.168.1.1", "interface": "en0", "device": "en0", "type": "ether", "flags": ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], "macaddress": "10:dd:b1:98:dd:27", "mtu": "1500", "options": ["PERFORMNUD", "DAD"], "media": "Unknown", "media_select": "autoselect", "media_type": "1000base", "media_options": ["full-duplex", "flow-control"], "status": "active", "address": "192.168.1.29", "netmask": "255.255.255.0", "network": "192.168.1.0", "broadcast": "192.168.1.255"}, "ansible_default_ipv6": {}, "ansible_all_ipv4_addresses": ["192.168.1.29"], "ansible_all_ipv6_addresses": ["fe80::8a:a5dc:beaa:bef5%en0", "fdd6:5fa2:b6eb:4997:cb1:56ac:81d:8eae", "fdd6:5fa2:b6eb:4997:fde1:ebb6:de14:b2c6", "fdd6:5fa2:b6eb:4997:e5d4:4028:155a:3dd0", "fdd6:5fa2:b6eb:4997:7c54:5ca:5f35:9ae7", "fe80::2150:2ee7:5a06:582d%utun0", "fe80::f155:9d9a:da95:f07c%utun1", "fe80::db1b:fa86:10a6:5743%utun2", "fe80::d237:9dc2:fd04:a8c5%utun3", "fe80::9724:15e7:a396:906d%utun4"], "ansible_model": "Macmini6,2", "ansible_product_name": "Macmini6,2", "ansible_osversion": "19H1615", "ansible_osrevision": "199506", "ansible_processor": "Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz", "ansible_processor_cores": "4", "ansible_processor_vcpus": "8", "ansible_memtotal_mb": 8192, "ansible_memfree_mb": 2996, "ansible_uptime_seconds": 251158, "ansible_user_id": "mike", "ansible_user_uid": 501, "ansible_user_gid": 20, "ansible_user_gecos": "Mike Potts", "ansible_user_dir": "/Users/mike", "ansible_user_shell": "/opt/brew/bin/bash", "ansible_real_user_id": 501, "ansible_effective_user_id": 501, "ansible_real_group_id": 20, "ansible_effective_group_id": 20, "ansible_local": {}, "ansible_system": "Darwin", "ansible_kernel": "19.6.0", "ansible_kernel_version": "Darwin Kernel Version 19.6.0: Sun Nov 14 19:58:51 PST 2021; root:xnu-6153.141.50~1/RELEASE_X86_64", "ansible_machine": "x86_64", "ansible_python_version": "3.8.2", "ansible_fqdn": "avon.local", "ansible_hostname": "avon", "ansible_nodename": "avon.local", "ansible_domain": "local", "ansible_userspace_bits": "64", "ansible_architecture": "x86_64", "ansible_userspace_architecture": "x86_64", "ansible_distribution": "MacOSX", "ansible_distribution_release": "19.6.0", "ansible_distribution_version": "10.15.7", "ansible_distribution_major_version": "10", "ansible_os_family": "Darwin", "ansible_ssh_host_key_dsa_public": "SNIP", "ansible_ssh_host_key_dsa_public_keytype": "ssh-dss", "ansible_ssh_host_key_rsa_public": "SNIP", "ansible_ssh_host_key_rsa_public_keytype": "ssh-rsa", "ansible_ssh_host_key_ecdsa_public": "SNIP", "ansible_ssh_host_key_ecdsa_public_keytype": "ecdsa-sha2-nistp256", "ansible_ssh_host_key_ed25519_public": "SNIP", "ansible_ssh_host_key_ed25519_public_keytype": "ssh-ed25519", "ansible_is_chroot": false, "ansible_lsb": {}, "ansible_fibre_channel_wwn": [], "ansible_virtualization_type": "", "ansible_virtualization_role": "", "ansible_virtualization_tech_guest": [], "ansible_virtualization_tech_host": [], "ansible_pkg_mgr": "homebrew", "ansible_apparmor": {"status": "disabled"}, "ansible_env": {"PERLBREW_SHELLRC_VERSION": "0.94", "MANPATH": "/opt/perl5/perls/perl-5.34.0/man:/usr/share/man:/Library/Apple/usr/share/man:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/share/man:/Library/Developer/CommandLineTools/usr/share/man", "PERLBREW_VERSION": "0.94", "PERLBREW_PERL": "perl-5.34.0", "TERM": "xterm", "SHELL": "/opt/brew/bin/bash", "SSH_CLIENT": "192.168.1.19 50714 22", "TMPDIR": "/var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/", "SSH_TTY": "/dev/ttys002", "LC_ALL": "en_US.UTF-8", "USER": "mike", "SSH_AUTH_SOCK": "/tmp/ssh-J3VcCKXGNz/agent.87549", "PERLBREW_ROOT": "/opt/perl5", "PATH": "/opt/perl5/bin:/opt/perl5/perls/perl-5.34.0/bin:/usr/bin:/bin:/usr/sbin:/sbin", "_": "/usr/bin/python3", "PWD": "/Users/mike", "LANG": "en_US.UTF-8", "PERLBREW_HOME": "/Users/mike/.perlbrew", "SHLVL": "1", "HOME": "/Users/mike", "PERLBREW_MANPATH": "/opt/perl5/perls/perl-5.34.0/man", "LC_TERMINAL_VERSION": "3.4.15", "LOGNAME": "mike", "PERLBREW_PATH": "/opt/perl5/bin:/opt/perl5/perls/perl-5.34.0/bin", "SSH_CONNECTION": "192.168.1.19 50714 192.168.1.29 22", "LC_TERMINAL": "iTerm2", "PERLBREW": "command perlbrew", "__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x0", "SDKROOT": "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk", "CPATH": "/usr/local/include", "LIBRARY_PATH": "/usr/local/lib", "__PYVENV_LAUNCHER__": "/Library/Developer/CommandLineTools/usr/bin/python3"}, "ansible_dns": {"nameservers": ["192.168.1.1"]}, "ansible_iscsi_iqn": "", "ansible_date_time": {"year": "2022", "month": "01", "weekday": "Saturday", "weekday_number": "6", "weeknumber": "00", "day": "01", "hour": "11", "minute": "10", "second": "01", "epoch": "1641064201", "epoch_int": "1641064201", "date": "2022-01-01", "time": "11:10:01", "iso8601_micro": "2022-01-01T19:10:01.638101Z", "iso8601": "2022-01-01T19:10:01Z", "iso8601_basic": "20220101T111001638101", "iso8601_basic_short": "20220101T111001", "tz": "PST", "tz_dst": "PDT", "tz_offset": "-0800"}, "ansible_selinux": {"status": "Missing selinux Python library"}, "ansible_selinux_python_present": false, "ansible_python": {"version": {"major": 3, "minor": 8, "micro": 2, "releaselevel": "final", "serial": 0}, "version_info": [3, 8, 2, "final", 0], "executable": "/Library/Developer/CommandLineTools/usr/bin/python3", "has_sslcontext": true, "type": "cpython"}, "ansible_fips": false, "ansible_hostnqn": "", "ansible_service_mgr": "launchd", "gather_subset": ["all"], "module_setup": true}, "invocation": {"module_args": {"gather_subset": ["all"], "gather_timeout": 10, "filter": [], "fact_path": "/etc/ansible/facts.d"}}}\r\n', b'Shared connection to 192.168.1.29 closed.\r\n')
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f avon '/bin/sh -c '"'"'rm -f -r /Users/mike/.ansible/tmp/ansible-tmp-1641064199.6377652-24297-82279717315237/ > /dev/null 2>&1 && sleep 0'"'"''
<avon> (0, b'', b'')
[WARNING]: Platform darwin on host avon is using the discovered Python interpreter at /usr/bin/python3,
but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-core/2.12/reference_appendices/interpreter_discovery.html for more
information.
ok: [avon]
META: ran handlers
META:
META:
META:
META:
META:
META:
META:
META:
META:
META:

TASK [python_dev : Install python 3 (with shared libaries for reticulate)] ******************************
task path: /Users/mike/src/setup/roles/python_dev/tasks/main.yml:91
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f avon '/bin/sh -c '"'"'echo ~mike && sleep 0'"'"''
<avon> (0, b'/Users/mike\n', b'')
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f avon '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /Users/mike/.ansible/tmp `"&& mkdir "` echo /Users/mike/.ansible/tmp/ansible-tmp-1641064202.1777742-24309-146991589279023 `" && echo ansible-tmp-1641064202.1777742-24309-146991589279023="` echo /Users/mike/.ansible/tmp/ansible-tmp-1641064202.1777742-24309-146991589279023 `" ) && sleep 0'"'"''
<avon> (0, b'ansible-tmp-1641064202.1777742-24309-146991589279023=/Users/mike/.ansible/tmp/ansible-tmp-1641064202.1777742-24309-146991589279023\n', b'')
Using module file /opt/brew/Cellar/ansible/5.1.0/libexec/lib/python3.10/site-packages/ansible/modules/command.py
<avon> PUT /Users/mike/.ansible/tmp/ansible-local-24294thvgz7ob/tmpxmx9vcwh TO /Users/mike/.ansible/tmp/ansible-tmp-1641064202.1777742-24309-146991589279023/AnsiballZ_command.py
<avon> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f '[avon]'
<avon> (0, b'sftp> put /Users/mike/.ansible/tmp/ansible-local-24294thvgz7ob/tmpxmx9vcwh /Users/mike/.ansible/tmp/ansible-tmp-1641064202.1777742-24309-146991589279023/AnsiballZ_command.py\n', b'')
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f avon '/bin/sh -c '"'"'chmod u+x /Users/mike/.ansible/tmp/ansible-tmp-1641064202.1777742-24309-146991589279023/ /Users/mike/.ansible/tmp/ansible-tmp-1641064202.1777742-24309-146991589279023/AnsiballZ_command.py && sleep 0'"'"''
<avon> (0, b'', b'')
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f -tt avon '/bin/sh -c '"'"'PATH=/opt/brew/bin:/opt/perl5/bin:/opt/perl5/perls/perl-5.34.0/bin:/usr/bin:/bin:/usr/sbin:/sbin /usr/bin/python3 /Users/mike/.ansible/tmp/ansible-tmp-1641064202.1777742-24309-146991589279023/AnsiballZ_command.py && sleep 0'"'"''
<avon> (1, b'\r\n{"changed": true, "stdout": "SHELL=/opt/brew/bin/bash\nPYENV_SHELL=bash\nSSH_AUTH_SOCK=/tmp/ssh-J3VcCKXGNz/agent.87549\nPERLBREW_PATH=/opt/perl5/bin:/opt/perl5/perls/perl-5.34.0/bin\nPERLBREW_HOME=/Users/mike/.perlbrew\nPERLBREW_SHELLRC_VERSION=0.94\nPWD=/Users/mike\nSDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk\nLOGNAME=mike\nMANPATH=/opt/perl5/perls/perl-5.34.0/man:/usr/share/man:/Library/Apple/usr/share/man:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/share/man:/Library/Developer/CommandLineTools/usr/share/man\nPERLBREW_PERL=perl-5.34.0\nPERLBREW=command perlbrew\nHOME=/Users/mike\nLANG=en_US.UTF-8\nPERLBREW_VERSION=0.94\nTMPDIR=/var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/\nLC_TERMINAL=iTerm2\nSSH_CONNECTION=192.168.1.19 50714 192.168.1.29 22\nTERM=xterm\nUSER=mike\nLIBRARY_PATH=/usr/local/lib\nLC_TERMINAL_VERSION=3.4.15\nPYTHON_CONFIGURE_OPTS=--enable-framework\nSHLVL=3\nSSH_CLIENT=192.168.1.19 50714 22\nLC_ALL=en_US.UTF-8\nPATH=/Users/mike/.pyenv/shims:/opt/brew/bin:/opt/brew/bin:/opt/perl5/bin:/opt/perl5/perls/perl-5.34.0/bin:/usr/bin:/bin:/usr/sbin:/sbin\nPERLBREW_ROOT=/opt/perl5\nSSH_TTY=/dev/ttys002\n__PYVENV_LAUNCHER__=/Library/Developer/CommandLineTools/usr/bin/python3\nCPATH=/usr/local/include\n__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0\nPERLBREW_MANPATH=/opt/perl5/perls/perl-5.34.0/man\n_=/usr/bin/env\npython-build: use openssl@1.1 from homebrew\npython-build: use readline from homebrew\npython-build: use tcl-tk from homebrew\npython-build: use readline from homebrew\npython-build: use zlib from xcode sdk", "stderr": "Installing Python-3.9.5...\n\nBUILD FAILED (OS X 10.15.7 using python-build 20180424)\n\nInspect or clean up the working tree at /var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/python-build.20220101111004.87798\nResults logged to /var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/python-build.20220101111004.87798.log\n\nLast 10 log lines:\n 

For what it's worth, here's the error from the python build file:

Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
isolated = 0
environment = 0
user site = 1
import site = 0
sys._base_executable = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
sys.base_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.base_exec_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.platlibdir = ‘lib’
sys.executable = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
sys.prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.exec_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.path = [
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python39.zip’,
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9’,
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/lib-dynload’,
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named ‘encodings’

Current thread 0x000000010f8c4dc0 (most recent call first):

generate-posix-vars failed
make: *** [pybuilddir.txt] Error 1


I've tried all variants on setting PYTHONHOME and PYTHONPATH, but no effect (and I believe I shouldn't have to set them since the script works via ssh).

Many thanks for any light that can be shed on this! It's the only part of my very large mac setup playbook that doesn't work!

Mike/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/lib-dynload

For what it's worth, here's the error from the python build file:

Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
isolated = 0
environment = 0
user site = 1
import site = 0
sys._base_executable = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
sys.base_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.base_exec_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.platlibdir = ‘lib’
sys.executable = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
sys.prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.exec_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.path = [
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python39.zip’,
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9’,
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/lib-dynload’,
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named ‘encodings’

Current thread 0x000000010f8c4dc0 (most recent call first):

generate-posix-vars failed
make: *** [pybuilddir.txt] Error 1


I've tried all variants on setting PYTHONHOME and PYTHONPATH, but no effect (and I believe I shouldn't have to set them since the script works via ssh).

Many thanks for any light that can be shed on this! It's the only part of my very large mac setup playbook that doesn't work!

Mike,\n ]\nFatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding\nPython runtime state: core initialized\nModuleNotFoundError: No module named 

For what it's worth, here's the error from the python build file:

Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
isolated = 0
environment = 0
user site = 1
import site = 0
sys._base_executable = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
sys.base_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.base_exec_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.platlibdir = ‘lib’
sys.executable = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
sys.prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.exec_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.path = [
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python39.zip’,
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9’,
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/lib-dynload’,
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named ‘encodings’

Current thread 0x000000010f8c4dc0 (most recent call first):

generate-posix-vars failed
make: *** [pybuilddir.txt] Error 1


I've tried all variants on setting PYTHONHOME and PYTHONPATH, but no effect (and I believe I shouldn't have to set them since the script works via ssh).

Many thanks for any light that can be shed on this! It's the only part of my very large mac setup playbook that doesn't work!

Mikeencodings

For what it's worth, here's the error from the python build file:

Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
isolated = 0
environment = 0
user site = 1
import site = 0
sys._base_executable = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
sys.base_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.base_exec_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.platlibdir = ‘lib’
sys.executable = ‘/Library/Developer/CommandLineTools/usr/bin/python3’
sys.prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.exec_prefix = ‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9’
sys.path = [
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python39.zip’,
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9’,
‘/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/lib-dynload’,
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named ‘encodings’

Current thread 0x000000010f8c4dc0 (most recent call first):

generate-posix-vars failed
make: *** [pybuilddir.txt] Error 1


I've tried all variants on setting PYTHONHOME and PYTHONPATH, but no effect (and I believe I shouldn't have to set them since the script works via ssh).

Many thanks for any light that can be shed on this! It's the only part of my very large mac setup playbook that doesn't work!

Mike\n\nCurrent thread 0x000000010f8c4dc0 (most recent call first):\n<no Python frame>\ngenerate-posix-vars failed\nmake: *** [pybuilddir.txt] Error 1", "rc": 1, "cmd": "/Users/mike/dopy.sh", "start": "2022-01-01 11:10:03.423582", "end": "2022-01-01 11:11:27.690673", "delta": "0:01:24.267091", "failed": true, "msg": "non-zero return code", "invocation": {"module_args": {"_raw_params": "/Users/mike/dopy.sh", "_uses_shell": true, "warn": false, "stdin_add_newline": true, "strip_empty_ends": true, "argv": null, "chdir": null, "executable": null, "creates": null, "removes": null, "stdin": null}}}\r\n', b'Shared connection to 192.168.1.29 closed.\r\n')
<avon> Failed to connect to the host via ssh: Shared connection to 192.168.1.29 closed.
<avon> ESTABLISH SSH CONNECTION FOR USER: mike
<avon> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mike"' -o ConnectTimeout=10 -o ControlPath=/Users/mike/.ansible/cp/edcc7ec59f avon '/bin/sh -c '"'"'rm -f -r /Users/mike/.ansible/tmp/ansible-tmp-1641064202.1777742-24309-146991589279023/ > /dev/null 2>&1 && sleep 0'"'"''
<avon> (0, b'', b'')
fatal: [avon]: FAILED! => {
"changed": true,
"cmd": "/Users/mike/dopy.sh",
"delta": "0:01:24.267091",
"end": "2022-01-01 11:11:27.690673",
"invocation": {
"module_args": {
"_raw_params": "/Users/mike/dopy.sh",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": false
}
},
"msg": "non-zero return code",
"rc": 1,
"start": "2022-01-01 11:10:03.423582",
"stderr": "Installing Python-3.9.5...\n\nBUILD FAILED (OS X 10.15.7 using python-build 20180424)\n\nInspect or clean up the working tree at /var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/python-build.20220101111004.87798\nResults logged to /var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/python-build.20220101111004.87798.log\n\nLast 10 log lines:\n '/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/lib-dynload',\n ]\nFatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding\nPython runtime state: core initialized\nModuleNotFoundError: No module named 'encodings'\n\nCurrent thread 0x000000010f8c4dc0 (most recent call first):\n<no Python frame>\ngenerate-posix-vars failed\nmake: *** [pybuilddir.txt] Error 1",
"stderr_lines": [
"Installing Python-3.9.5...",
"",
"BUILD FAILED (OS X 10.15.7 using python-build 20180424)",
"",
"Inspect or clean up the working tree at /var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/python-build.20220101111004.87798",
"Results logged to /var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/python-build.20220101111004.87798.log",
"",
"Last 10 log lines:",
" '/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/lib-dynload',",
" ]",
"Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding",
"Python runtime state: core initialized",
"ModuleNotFoundError: No module named 'encodings'",
"",
"Current thread 0x000000010f8c4dc0 (most recent call first):",
"<no Python frame>",
"generate-posix-vars failed",
"make: *** [pybuilddir.txt] Error 1"
],
"stdout": "SHELL=/opt/brew/bin/bash\nPYENV_SHELL=bash\nSSH_AUTH_SOCK=/tmp/ssh-J3VcCKXGNz/agent.87549\nPERLBREW_PATH=/opt/perl5/bin:/opt/perl5/perls/perl-5.34.0/bin\nPERLBREW_HOME=/Users/mike/.perlbrew\nPERLBREW_SHELLRC_VERSION=0.94\nPWD=/Users/mike\nSDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk\nLOGNAME=mike\nMANPATH=/opt/perl5/perls/perl-5.34.0/man:/usr/share/man:/Library/Apple/usr/share/man:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/share/man:/Library/Developer/CommandLineTools/usr/share/man\nPERLBREW_PERL=perl-5.34.0\nPERLBREW=command perlbrew\nHOME=/Users/mike\nLANG=en_US.UTF-8\nPERLBREW_VERSION=0.94\nTMPDIR=/var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/\nLC_TERMINAL=iTerm2\nSSH_CONNECTION=192.168.1.19 50714 192.168.1.29 22\nTERM=xterm\nUSER=mike\nLIBRARY_PATH=/usr/local/lib\nLC_TERMINAL_VERSION=3.4.15\nPYTHON_CONFIGURE_OPTS=--enable-framework\nSHLVL=3\nSSH_CLIENT=192.168.1.19 50714 22\nLC_ALL=en_US.UTF-8\nPATH=/Users/mike/.pyenv/shims:/opt/brew/bin:/opt/brew/bin:/opt/perl5/bin:/opt/perl5/perls/perl-5.34.0/bin:/usr/bin:/bin:/usr/sbin:/sbin\nPERLBREW_ROOT=/opt/perl5\nSSH_TTY=/dev/ttys002\n__PYVENV_LAUNCHER__=/Library/Developer/CommandLineTools/usr/bin/python3\nCPATH=/usr/local/include\n__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0\nPERLBREW_MANPATH=/opt/perl5/perls/perl-5.34.0/man\n_=/usr/bin/env\npython-build: use openssl@1.1 from homebrew\npython-build: use readline from homebrew\npython-build: use tcl-tk from homebrew\npython-build: use readline from homebrew\npython-build: use zlib from xcode sdk",
"stdout_lines": [
"SHELL=/opt/brew/bin/bash",
"PYENV_SHELL=bash",
"SSH_AUTH_SOCK=/tmp/ssh-J3VcCKXGNz/agent.87549",
"PERLBREW_PATH=/opt/perl5/bin:/opt/perl5/perls/perl-5.34.0/bin",
"PERLBREW_HOME=/Users/mike/.perlbrew",
"PERLBREW_SHELLRC_VERSION=0.94",
"PWD=/Users/mike",
"SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk",
"LOGNAME=mike",
"MANPATH=/opt/perl5/perls/perl-5.34.0/man:/usr/share/man:/Library/Apple/usr/share/man:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/share/man:/Library/Developer/CommandLineTools/usr/share/man",
"PERLBREW_PERL=perl-5.34.0",
"PERLBREW=command perlbrew",
"HOME=/Users/mike",
"LANG=en_US.UTF-8",
"PERLBREW_VERSION=0.94",
"TMPDIR=/var/folders/5p/ks9xtgvx4sb8p2rcfzp5ppmc0000gn/T/",
"LC_TERMINAL=iTerm2",
"SSH_CONNECTION=192.168.1.19 50714 192.168.1.29 22",
"TERM=xterm",
"USER=mike",
"LIBRARY_PATH=/usr/local/lib",
"LC_TERMINAL_VERSION=3.4.15",
"PYTHON_CONFIGURE_OPTS=--enable-framework",
"SHLVL=3",
"SSH_CLIENT=192.168.1.19 50714 22",
"LC_ALL=en_US.UTF-8",
"PATH=/Users/mike/.pyenv/shims:/opt/brew/bin:/opt/brew/bin:/opt/perl5/bin:/opt/perl5/perls/perl-5.34.0/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"PERLBREW_ROOT=/opt/perl5",
"SSH_TTY=/dev/ttys002",
"__PYVENV_LAUNCHER__=/Library/Developer/CommandLineTools/usr/bin/python3",
"CPATH=/usr/local/include",
"__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0",
"PERLBREW_MANPATH=/opt/perl5/perls/perl-5.34.0/man",
"_=/usr/bin/env",
"python-build: use openssl@1.1 from homebrew",
"python-build: use readline from homebrew",
"python-build: use tcl-tk from homebrew",
"python-build: use readline from homebrew",
"python-build: use zlib from xcode sdk"
]
}

PLAY RECAP **********************************************************************************************
avon : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

For what it’s worth, here’s the error from the python build file:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = '/Library/Developer/CommandLineTools/usr/bin/python3'
isolated = 0
environment = 0
user site = 1
import site = 0
sys._base_executable = '/Library/Developer/CommandLineTools/usr/bin/python3'
sys.base_prefix = '/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9'
sys.base_exec_prefix = '/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9'
sys.platlibdir = 'lib'
sys.executable = '/Library/Developer/CommandLineTools/usr/bin/python3'
sys.prefix = '/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9'
sys.exec_prefix = '/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9'
sys.path = [
'/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
'/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
'/Users/mike/.pyenv/versions/3.9.5/Library/Frameworks/Python.framework/Versions/3.9/lib/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x000000010f8c4dc0 (most recent call first):
<no Python frame>
generate-posix-vars failed
make: *** [pybuilddir.txt] Error 1

I’ve tried all variants on setting PYTHONHOME and PYTHONPATH, but no effect (and I believe I shouldn’t have to set them since the script works via ssh).

Many thanks for any light that can be shed on this! It’s the only part of my very large mac setup playbook that doesn’t work!

Mike

pyenv involves a lot of environment specific chicanery. Why not simply
use the MacOS installation package at:
https://www.python.org/downloads/release/python-3101/ ?

Thanks for the suggestion, but I do rely on pyenv a lot: I have to have multiple versions of python (2 and 3) all available, and I use virtual environments as well, so even if I installed a python from python.org, I’d still want to be able to use pyenv.

Quick reply to my own thread: I should have kept at this before posting, because I just tried adding this to my script (based on a comparison of the envs):

unset LIBRARY_PATH
unset PYVENV_LAUNCHER
unset CPATH

and now the ansible install works! I’ll zero in on the culprit now, but basically this is resolved for me now.

Quick reply to my own thread: I should have kept at this before posting, because I just tried adding this to my script (based on a comparison of the envs):

unset LIBRARY_PATH
unset __PYVENV_LAUNCHER__
unset CPATH

Also known as "environment specific chicanery". I'm glad you were able
to resolve this.

LOL yes indeed :slight_smile:

Turns out in the end I just had to unset PYTHON_LAUNCHER (which is apparently a Mac-specific security thing that’s set by the system python). The other two flags (CMAKE and LIBRARY_PATH) are apparently ignored.

One weird thing still: although this now works if I use ansible to copy the script to the host:

export PATH=/opt/brew/bin:$PATH
eval “$(pyenv init --path)”
eval “$(pyenv init -)”
export PYTHON_CONFIGURE_OPTS=“–enable-framework”
unset PYVENV_LAUNCHER
pyenv install 3.9.5

and then use the command module to execute it:

- name: Install python 3 (with shared libaries for reticulate)
command: "{{ homebrew_prefix }}/bin/bash scoobydoo.sh"
environment:
PATH: "{{ homebrew_prefix }}/bin:{{ ansible_env.PATH }}"

Unfortunately, when I try to execute it in one step:

- name: Install python 3 (with shared libaries for reticulate)
shell: |
export PATH=/opt/brew/bin:$PATH
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
export PYTHON_CONFIGURE_OPTS="--enable-framework"
unset __PYTHON_LAUNCHER__
pyenv install 3.9.5
environment:
PATH: "{{ homebrew_prefix }}/bin:{{ ansible_env.PATH }}"

I get the same error as before. (And of course I can’t use the pyenv module directly because it also generates the same error (and I don’t know how to unset PYTHON_LAUNCHER in that case. So for now my solution is necessarily:

  1. create the script on the host (copy module)
  2. execute the script on the host (command module)

Not elegant, but functional at least!

OK here’s the final (tested) solution in case anyone hits the same issue:

- name: Create a temporary python install script on the host
copy:
dest: "{{ ansible_env.HOME }}/tmp-install-python.sh"
content: |
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
unset __PYVENV_LAUNCHER__
pyenv install $1
register: generic_python_script_created

- name: Install python 3 (with framework, for reticulate) via created script
command: "{{ homebrew_prefix }}/bin/bash tmp-install-python.sh {{ python_three_version }}"
environment:
PATH: "{{ homebrew_prefix }}/bin:{{ ansible_env.PATH }}"
PYTHON_CONFIGURE_OPTS: "--enable-framework"
when:
- python_three_version not in pyenv_installed.versions
- generic_python_script_created is succeeded
register: python_three_installed

- name: Remove the temporary python install script again
file:
path: "{{ ansible_env.HOME }}/tmp-install-python.sh"
state: absent
when: generic_python_script_created is succeeded

and, just for completeness, I also successfully install python 2 (without the framework) using suzuki-shunsuke.pyenv-module (with one caveat: I have to temporarily symlink homebrew’s pyenv into ~/.pyenv/bin because that’s where the pyenv module expects to find it):

- name: Create a temporary symlink of the homebrew bin dir, so the pyenv module can find pyenv.
file:
src: "{{ homebrew_prefix }}/bin"
dest: "{{ pyenv_root }}/bin"
state: link
register: pyenv_symlink_created

- name: Install python 2 (without framework)

pyenv:
version: "{{ python_two_version }}"
pyenv_root: "{{ pyenv_root }}"
environment:
PATH: "{{ homebrew_prefix }}/bin:{{ ansible_env.PATH }}"
when:
- python_two_version not in pyenv_installed.versions
- pyenv_symlink_created is succeeded
register: python_two_installed