|
20 | 20 | become: true
|
21 | 21 | become_method: sudo
|
22 | 22 | tasks:
|
23 |
| - - name: Load a variable file based on the OS type, or a default if not found. Using free-form to specify the file. |
| 23 | + |
| 24 | + - name: Get python version |
| 25 | + # This will be deprecated in Ansible 2.9 in favor of python_requirements_info but |
| 26 | + # it is not yet available in Ansible 2.7.9 |
| 27 | + python_requirements_facts: |
| 28 | + register: pri |
| 29 | + failed_when: "pri == None or pri.python_version == None or pri.python_version == ''" |
| 30 | + |
| 31 | + - name: Load a variable file based on the OS type. |
24 | 32 | include_vars:
|
25 | 33 | file: "{{ item }}"
|
26 | 34 | with_first_found:
|
27 |
| - - "vars/{{ ansible_distribution }}.yml" |
28 |
| - - "vars/{{ ansible_os_family }}.yml" |
| 35 | + - "vars/{{ ansible_os_family }}-py{{pri.python_version | replace('\n', '') | regex_replace('^(\\d+).*', '\\1') }}.yml" |
| 36 | + - "vars/{{ ansible_os_family }}-py{{pri.python_version | replace('\n', '') | regex_replace('^(\\d+).*', '\\1') }}.yml" |
29 | 37 |
|
30 |
| - - name: install prerequirements |
31 |
| - package: |
32 |
| - name: "{{item}}" |
| 38 | + - name: RedHat - install prerequisites |
| 39 | + yum: |
| 40 | + name: "{{install_packages}}" |
33 | 41 | state: present
|
34 |
| - with_items: "{{install_packages}}" |
35 |
| - |
36 |
| - - name: Check if distribution has easy_install or needs a pip3 installation |
37 |
| - set_fact: |
38 |
| - easy_install_available: "{{ ansible_distribution != 'Ubuntu' or ansible_distribution_major_version is version(18, '<') }}" |
| 42 | + update_cache: yes |
| 43 | + when: ansible_os_family == 'RedHat' |
39 | 44 |
|
40 |
| - - name: Ensure pip is installed using easy_install when availabe |
41 |
| - easy_install: |
42 |
| - name: pip |
43 |
| - state: latest |
44 |
| - when: easy_install_available |
45 | 45 |
|
46 |
| - - name: Install python3-pip when easy_install in not available |
| 46 | + - name: Debian - install prerequisites |
47 | 47 | apt:
|
48 |
| - name: |
49 |
| - - python3-pip |
| 48 | + name: "{{ install_packages }}" |
50 | 49 | state: present
|
51 | 50 | update_cache: yes
|
52 |
| - when: not easy_install_available |
| 51 | + when: ansible_os_family == 'Debian' |
53 | 52 |
|
54 |
| - - name: install using pip |
| 53 | + - name: Install latest Pip version |
55 | 54 | pip:
|
56 |
| - name: |
57 |
| - - "ansible=={{ANSIBLE_VERSION}}" |
58 |
| - - "jmespath==0.9.4" |
59 |
| - - "netaddr==0.7.19" |
60 |
| - when: ANSIBLE_EXTRA_PACKAGE_REPOSITORY == "" |
| 55 | + name: "pip" |
| 56 | + state: latest |
| 57 | + executable: "{{pip_cmd}}" |
61 | 58 |
|
62 |
| - - name: install using pip package repository "{{ANSIBLE_EXTRA_PACKAGE_REPOSITORY}}" |
| 59 | + - name: install Ansible using Pip |
63 | 60 | pip:
|
64 | 61 | name:
|
65 | 62 | - "ansible=={{ANSIBLE_VERSION}}"
|
66 | 63 | - "jmespath==0.9.4"
|
67 | 64 | - "netaddr==0.7.19"
|
68 |
| - extra_args: --extra-index-url "{{ANSIBLE_EXTRA_PACKAGE_REPOSITORY}}" |
69 |
| - when: ANSIBLE_EXTRA_PACKAGE_REPOSITORY != "" |
| 65 | + executable: "{{pip_cmd}}" |
| 66 | + extra_args: "{{ '--extra-index-url {}'.format(ANSIBLE_EXTRA_PACKAGE_REPOSITORY) if ANSIBLE_EXTRA_PACKAGE_REPOSITORY != '' else ''}}" |
0 commit comments