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
```
On Saturday, 1 January 2022 at 17:34:31 UTC-8 maspotts wrote:

> LOL yes indeed :)
>
> 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!
>
>
> On Saturday, 1 January 2022 at 17:09:38 UTC-8 [email protected] wrote:
>
>> On Sat, Jan 1, 2022 at 7:47 PM maspotts <[email protected]> wrote: 
>> > 
>> > 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. 
>>
>> > and now the ansible install works! I'll zero in on the culprit now, but 
>> basically this is resolved for me now. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f41412ef-6e3c-4908-a6cb-df6eee53bd15n%40googlegroups.com.

Reply via email to