Skip to content

Commit

Permalink
Update variable names in "python" Ansible role.
Browse files Browse the repository at this point in the history
  • Loading branch information
damiendart committed Jan 24, 2024
1 parent 8c56775 commit 1b73950
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions roles/python/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
# Python binary archive download. See also "python__archive_url" and
# "python__version". Python binary archives and checksums are available
# at <https://github.com/indygreg/python-build-standalone/releases>.
python__archive_checksum: 'sha256:9a2f2bb9fca7f31502e102306fbeed8ceb7f634f4376a08f9f630c1982f62fcb'
python__python_archive_checksum: 'sha256:9a2f2bb9fca7f31502e102306fbeed8ceb7f634f4376a08f9f630c1982f62fcb'

# A string containing the URL to the binary archive.
python__archive_url: 'https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-x86_64_v3-unknown-linux-gnu-install_only.tar.gz'
python__python_archive_url: 'https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-x86_64_v3-unknown-linux-gnu-install_only.tar.gz'

# A string containing the version of Python to install.
python__version: '3.11.6'
python__python_version: '3.11.6'


# The following variables will have host-specific and/or sensitive
Expand Down
18 changes: 9 additions & 9 deletions roles/python/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@

- name: 'Get status of existing non-system Python installation'
ansible.builtin.stat:
path: "/usr/local/python/bin/python{{ python__version | regex_search('\\d.\\d{1,}') }}"
path: "/usr/local/python/bin/python{{ python__python_version | regex_search('\\d.\\d{1,}') }}"
changed_when: false
register: __python_binary

- name: 'Get version of existing non-system Python installation'
ansible.builtin.command: "/usr/local/python/bin/python{{ python__version | regex_search('\\d.\\d{1,}') }} --version"
ansible.builtin.command: "/usr/local/python/bin/python{{ python__python_version | regex_search('\\d.\\d{1,}') }} --version"
changed_when: false
failed_when: false
register: __python_version
when: __python_binary.stat.exists

- name: 'Ensure Python {{ python__version }} is installed' # noqa: name[template]
when: python__version not in (__python_version.stdout | default('') | trim)
- name: 'Ensure Python {{ python__python_version }} is installed' # noqa: name[template]
when: python__python_version not in (__python_version.stdout | default('') | trim)
block:
- name: 'Ensure the Python binary archive is downloaded'
ansible.builtin.get_url:
checksum: '{{ python__archive_checksum }}'
dest: '{{ python__download_cache_directory }}/{{ python__archive_url | basename }}'
checksum: '{{ python__python_archive_checksum }}'
dest: '{{ python__download_cache_directory }}/{{ python__python_archive_url | basename }}'
group: 'root'
mode: 0755
owner: 'root'
url: '{{ python__archive_url }}'
url: '{{ python__python_archive_url }}'

- name: 'Ensure existing Python installation is removed'
ansible.builtin.file:
Expand All @@ -57,14 +57,14 @@
path: '/usr/local/python'
state: 'directory'

- name: 'Ensure Python {{ python__version }} is installed' # noqa: name[template]
- name: 'Ensure Python {{ python__python_version }} is installed' # noqa: name[template]
ansible.builtin.unarchive:
dest: '/usr/local/python'
extra_opts:
- '--strip-components=1'
group: 'root'
owner: 'root'
src: '{{ python__download_cache_directory }}/{{ python__archive_url | basename }}'
src: '{{ python__download_cache_directory }}/{{ python__python_archive_url | basename }}'

- name: 'Ensure Ansible local facts directory exists'
ansible.builtin.file:
Expand Down
2 changes: 1 addition & 1 deletion roles/python/templates/python.fact.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
#}
{
"bin_dir": "/usr/local/python/bin",
"version": "{{ python__version }}"
"version": "{{ python__python_version }}"
}

0 comments on commit 1b73950

Please sign in to comment.