-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve idempotency by allowing the user to uninstall existing Python…
… interpreters that lack desired Python configure options (#42) * Bump require Ansible version from 1.9.4 to 2.5.0 * Add but don't use custom fact checker that checks if desired Python installations are missing or need to be re-compiled * Use the facts checker to check existing installations for pyenv_python_configure_opts options * Uninstall existing python installations that have the wrong configure flags * Install python versions using the 'environment' and 'args' keys and also use the creates options * Uninstall Python intrepreters w/ wrong configure opts only when the user chooses to
- Loading branch information
1 parent
77d0c2d
commit 4983761
Showing
8 changed files
with
90 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
- name: Create folder for custom facts | ||
file: | ||
path: /etc/ansible/facts.d | ||
state: directory | ||
|
||
- name: Copy over check-configure-options.py | ||
template: | ||
src: templates/check-configure-options.py.j2 | ||
dest: /etc/ansible/facts.d/check-configure-options.py | ||
owner: "{{ pyenv_owner }}" | ||
group: "{{ pyenv_owner }}" | ||
mode: "0755" | ||
|
||
- name: Copy over python_check fact file | ||
template: | ||
src: templates/pyenv_python_installations.fact.j2 | ||
dest: /etc/ansible/facts.d/pyenv_python_installations.fact | ||
owner: "{{ pyenv_owner }}" | ||
group: "{{ pyenv_owner }}" | ||
mode: "0755" | ||
|
||
- name: Reload setup to gather custom facts | ||
setup: | ||
filter: ansible_local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
--- | ||
- include: custom_facts.yml | ||
become: true | ||
become_user: "{{ pyenv_owner }}" | ||
when: pyenv_env == "user" | ||
|
||
- include: custom_facts.yml | ||
become: true | ||
when: pyenv_env == "system" | ||
|
||
- include: Darwin.yml | ||
when: ansible_os_family == "Darwin" | ||
|
||
- include: Debian.yml | ||
when: ansible_os_family == "Debian" | ||
|
||
- include: RedHat.yml | ||
when: ansible_os_family == "RedHat" | ||
|
||
|
||
- include: install.yml | ||
become: true | ||
become_user: "{{ pyenv_owner }}" | ||
when: pyenv_env == "user" | ||
|
||
- include: install.yml | ||
become: true | ||
when: pyenv_env == "system" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import sysconfig | ||
|
||
config_args = sysconfig.get_config_var("CONFIG_ARGS") | ||
config_args = config_args.replace("'", "").split() | ||
required_args = {{ pyenv_python_configure_opts.split() }} | ||
print(all(s in config_args for s in required_args)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
configure_opts_checker="/etc/ansible/facts.d/check-configure-options.py" | ||
|
||
declare -a installs_to_check=({{ " ".join(pyenv_python_versions) }}) | ||
declare -a to_reinstall=() | ||
declare -a to_install=() | ||
|
||
# Join array to string | ||
function join { local IFS="$1"; shift; echo "[$*]"; } | ||
|
||
for version in "${installs_to_check[@]}" | ||
do | ||
py_installation="{{ pyenv_path }}/versions/$version/bin/python" | ||
|
||
if [[ -x "$py_installation" ]]; then | ||
is_valid_install=$("$py_installation" "$configure_opts_checker") | ||
|
||
if [[ $is_valid_install =~ "False" ]]; then | ||
to_reinstall+=("\"$version\"") | ||
fi | ||
else | ||
to_install+=("\"$version\"") | ||
fi | ||
done | ||
|
||
to_reinstall_str=$(join , ${to_reinstall[@]}) | ||
to_install_str=$(join , ${to_install[@]}) | ||
printf "{ \"to_reinstall\": "$to_reinstall_str", \"to_install\": "$to_install_str" }\n" |