diff --git a/CHANGELOG.md b/CHANGELOG.md index c8cfa21d..f5a52c90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * Add docker container property to set the shared memory size ([GH-129](https://github.com/ystia/forge/issues/129)) +### BUG FIXES + +* Installation of Consul and Ansible fails on recent Centos for GCP images ([GH-131](https://github.com/ystia/forge/issues/131)) + ## 2.2.0 (April 17, 2020) ### NEW COMPONENTS diff --git a/org/ystia/ansible/linux/ansible/playbooks/create.yml b/org/ystia/ansible/linux/ansible/playbooks/create.yml index f4336cb0..8ed8d259 100644 --- a/org/ystia/ansible/linux/ansible/playbooks/create.yml +++ b/org/ystia/ansible/linux/ansible/playbooks/create.yml @@ -20,50 +20,47 @@ become: true become_method: sudo tasks: - - name: Load a variable file based on the OS type, or a default if not found. Using free-form to specify the file. + + - name: Get python version + # This will be deprecated in Ansible 2.9 in favor of python_requirements_info but + # it is not yet available in Ansible 2.7.9 + python_requirements_facts: + register: pri + failed_when: "pri == None or pri.python_version == None or pri.python_version == ''" + + - name: Load a variable file based on the OS type. include_vars: file: "{{ item }}" with_first_found: - - "vars/{{ ansible_distribution }}.yml" - - "vars/{{ ansible_os_family }}.yml" + - "vars/{{ ansible_os_family }}-py{{pri.python_version | replace('\n', '') | regex_replace('^(\\d+).*', '\\1') }}.yml" + - "vars/{{ ansible_os_family }}-py{{pri.python_version | replace('\n', '') | regex_replace('^(\\d+).*', '\\1') }}.yml" - - name: install prerequirements - package: - name: "{{item}}" + - name: RedHat - install prerequisites + yum: + name: "{{install_packages}}" state: present - with_items: "{{install_packages}}" - - - name: Check if distribution has easy_install or needs a pip3 installation - set_fact: - easy_install_available: "{{ ansible_distribution != 'Ubuntu' or ansible_distribution_major_version is version(18, '<') }}" + update_cache: yes + when: ansible_os_family == 'RedHat' - - name: Ensure pip is installed using easy_install when availabe - easy_install: - name: pip - state: latest - when: easy_install_available - - name: Install python3-pip when easy_install in not available + - name: Debian - install prerequisites apt: - name: - - python3-pip + name: "{{ install_packages }}" state: present update_cache: yes - when: not easy_install_available + when: ansible_os_family == 'Debian' - - name: install using pip + - name: Install latest Pip version pip: - name: - - "ansible=={{ANSIBLE_VERSION}}" - - "jmespath==0.9.4" - - "netaddr==0.7.19" - when: ANSIBLE_EXTRA_PACKAGE_REPOSITORY == "" + name: "pip" + state: latest + executable: "{{pip_cmd}}" - - name: install using pip package repository "{{ANSIBLE_EXTRA_PACKAGE_REPOSITORY}}" + - name: install Ansible using Pip pip: name: - "ansible=={{ANSIBLE_VERSION}}" - "jmespath==0.9.4" - "netaddr==0.7.19" - extra_args: --extra-index-url "{{ANSIBLE_EXTRA_PACKAGE_REPOSITORY}}" - when: ANSIBLE_EXTRA_PACKAGE_REPOSITORY != "" + executable: "{{pip_cmd}}" + extra_args: "{{ '--extra-index-url {}'.format(ANSIBLE_EXTRA_PACKAGE_REPOSITORY) if ANSIBLE_EXTRA_PACKAGE_REPOSITORY != ''}}" diff --git a/org/ystia/ansible/linux/ansible/playbooks/vars/Debian.yml b/org/ystia/ansible/linux/ansible/playbooks/vars/Debian-py2.yml similarity index 96% rename from org/ystia/ansible/linux/ansible/playbooks/vars/Debian.yml rename to org/ystia/ansible/linux/ansible/playbooks/vars/Debian-py2.yml index 5b51918d..bc107045 100644 --- a/org/ystia/ansible/linux/ansible/playbooks/vars/Debian.yml +++ b/org/ystia/ansible/linux/ansible/playbooks/vars/Debian-py2.yml @@ -19,4 +19,6 @@ install_packages: - make - python2 - python2-dev - - virtualenv + - python-pip + +pip_cmd: "pip" \ No newline at end of file diff --git a/org/ystia/ansible/linux/ansible/playbooks/vars/Debian-py3.yml b/org/ystia/ansible/linux/ansible/playbooks/vars/Debian-py3.yml new file mode 100644 index 00000000..a7b915d9 --- /dev/null +++ b/org/ystia/ansible/linux/ansible/playbooks/vars/Debian-py3.yml @@ -0,0 +1,24 @@ +# +# Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +install_packages: + - gcc + - make + - python3 + - python3-dev + - python3-pip + +pip_cmd: "pip3" \ No newline at end of file diff --git a/org/ystia/ansible/linux/ansible/playbooks/vars/RedHat.yml b/org/ystia/ansible/linux/ansible/playbooks/vars/RedHat-py2.yml similarity index 96% rename from org/ystia/ansible/linux/ansible/playbooks/vars/RedHat.yml rename to org/ystia/ansible/linux/ansible/playbooks/vars/RedHat-py2.yml index 24b96c0e..e1e43f7a 100644 --- a/org/ystia/ansible/linux/ansible/playbooks/vars/RedHat.yml +++ b/org/ystia/ansible/linux/ansible/playbooks/vars/RedHat-py2.yml @@ -19,4 +19,6 @@ install_packages: - make - python2 - python2-devel - - python-virtualenv + - python-pip + +pip_cmd: "pip" \ No newline at end of file diff --git a/org/ystia/ansible/linux/ansible/playbooks/vars/RedHat-py3.yml b/org/ystia/ansible/linux/ansible/playbooks/vars/RedHat-py3.yml new file mode 100644 index 00000000..093e9333 --- /dev/null +++ b/org/ystia/ansible/linux/ansible/playbooks/vars/RedHat-py3.yml @@ -0,0 +1,24 @@ +# +# Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +install_packages: + - gcc + - make + - python3 + - python3-devel + - python3-pip + +pip_cmd: "pip3" diff --git a/org/ystia/experimental/consul/linux/ansible/playbooks/consul_install.yaml b/org/ystia/experimental/consul/linux/ansible/playbooks/consul_install.yaml index 2cc92195..01f54679 100644 --- a/org/ystia/experimental/consul/linux/ansible/playbooks/consul_install.yaml +++ b/org/ystia/experimental/consul/linux/ansible/playbooks/consul_install.yaml @@ -39,7 +39,7 @@ register: apt_res retries: 3 until: apt_res is success - when: ansible_distribution == 'Ubuntu' + when: ansible_os_family == 'Debian' - name: Backup original resolve.conf copy: @@ -60,11 +60,30 @@ dnsmasq_conf_log: "DAEMON" when: INSTALL_DNSMASQ == "true" + - name: Get python version + # This will be deprecated in Ansible 2.9 in favor of python_requirements_info but + # it is not yet available in Ansible 2.7.9 + python_requirements_facts: + register: pri + failed_when: "pri == None or pri.python_version == None or pri.python_version == ''" + + - name: Set python version for pip + set_fact: + python_pip_pkg: "python3-pip" + pip_cmd: "pip3" + + - name: Set python 2 version for pip + set_fact: + python_pip_pkg: "python-pip" + pip_cmd: "pip" + when: pri.python_version is version('3', '<') + - name: RedHat - install prerequisites yum: name: - zip - unzip + - "{{ python_pip_pkg }}" state: present update_cache: yes when: ansible_os_family == 'RedHat' @@ -74,10 +93,27 @@ name: - zip - unzip + - "{{ python_pip_pkg }}" state: present update_cache: yes when: ansible_os_family == 'Debian' + - name: Install latest Pip version + pip: + name: "pip" + state: latest + executable: "{{pip_cmd}}" + + - name: Copy python requirements + copy: + src: requirements.txt + dest: "{{ INSTALL_DIR }}" + + - name: Install python requirements + pip: + requirements: "{{ INSTALL_DIR }}/requirements.txt" + executable: "{{pip_cmd}}" + - name: create Consul group group: name=consul @@ -124,7 +160,7 @@ mode: "u=rx,g=rx,o=rx" - name: Install consul systemd unit - template: + template: src: consul.service.j2 dest: "/etc/systemd/system/consul.service" mode: "u=rw,g=rw,o=r" @@ -137,34 +173,7 @@ state: stopped - name: Install consul maintenance script - template: + template: src: consul_maintenance.sh.j2 dest: "{{INSTALL_DIR}}/consul_maintenance.sh" mode: "u=rwx,g=rx,o=rx" - - - name: Check if distribution has easy_install or needs a pip3 installation - set_fact: - easy_install_available: "{{ ansible_distribution != 'Ubuntu' or ansible_distribution_major_version is version(18, '<') }}" - - - name: Ensure pip is installed using easy_install when availabe - easy_install: - name: pip - state: latest - when: easy_install_available - - - name: Install python3-pip when easy_install in not available - apt: - name: - - python3-pip - state: present - update_cache: yes - when: not easy_install_available - - - name: Install requirements - copy: - src: requirements.txt - dest: "{{ INSTALL_DIR }}" - - - name: Install python requirements - pip: - requirements: "{{ INSTALL_DIR }}/requirements.txt" \ No newline at end of file