Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

Commit 511f8f9

Browse files
authored
Merge pull request #204 from ni-fgenois/feature/updatable-globals
Allow updating the pyenv global versions file
2 parents 2e39c9e + 459389c commit 511f8f9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

tasks/install.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,23 @@
8585
with_items: "{{ pyenv_virtualenvs }}"
8686
when: pyenv_enable_virtualenvs
8787

88-
- name: "Set pyenv global {{ pyenv_global }}"
89-
ansible.builtin.shell: . {{ pyenvrc_path }}/.pyenvrc && pyenv global {{ pyenv_global | join(' ') }} && pyenv rehash
90-
args:
91-
creates: "{{ pyenv_path }}/version"
88+
- name: Update the pyenv globals
9289
when: pyenv_global is defined
90+
vars:
91+
pyenv_global_versions_path: "{{ pyenv_path }}/version"
92+
block:
93+
- name: "Does pyenv globals file exist?"
94+
ansible.builtin.stat:
95+
path: "{{ pyenv_global_versions_path }}"
96+
register: _pyenv_globals_file
97+
- name: "Read the pyenv global versions"
98+
ansible.builtin.slurp:
99+
src: "{{ pyenv_global_versions_path }}"
100+
register: _pyenv_globals_file_content
101+
when: _pyenv_globals_file.stat.exists
102+
- name: "Set pyenv global {{ pyenv_global }}"
103+
ansible.builtin.shell: . {{ pyenvrc_path }}/.pyenvrc && pyenv global {{ pyenv_global | join(' ') }} && pyenv rehash
104+
changed_when: true
105+
when:
106+
- _pyenv_globals_file.stat.exists
107+
- (_pyenv_globals_file_content.content | b64decode | split('\n') | select() | list) != pyenv_global

0 commit comments

Comments
 (0)