From: Anil Belur Date: Thu, 6 Oct 2022 13:04:11 +0000 (+1000) Subject: Feat!: Install ansible tools from PyPI X-Git-Tag: v0.12.0^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=bc610a5002a70804fa0ccdfdc92308e4bfbe1881;p=releng%2Fcommon-packer.git Feat!: Install ansible tools from PyPI Install ansible through system packages causes dependencies conflicts on CentOS 8 platform therefore update packer templates to use ansible provisioner created through venv. Error: Problem: package ansible-5.4.0-3.el8.noarch requires (ansible-core >= 2.12.2 with ansible-core < 2.13), but none of the providers can be installed Issue-ID: RELENG-4473 Change-Id: I1d562386b4408c9674271e813dcd2aea6632e709 Signed-off-by: Anil Belur --- diff --git a/ansible-galaxy.sh b/ansible-galaxy.sh index 1d9a080..07b0049 100755 --- a/ansible-galaxy.sh +++ b/ansible-galaxy.sh @@ -13,6 +13,15 @@ set -eu -o pipefail -o noglob echo "----> ansible-galaxy.sh" +wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/jenkins-init-scripts/lf-env.sh \ + -O ~/lf-env.sh + +# shellcheck disable=SC1090 +. ~/lf-env.sh + +lf-activate-venv --python python3 --venv-file "/tmp/.ansible_venv" \ + ansible~=2.9.27 + ansible_roles_path=${1:-.galaxy} ansible_requirements_file=${2:-requirements.yaml} script_dir=$(dirname "$0") diff --git a/ansible-playbook.sh b/ansible-playbook.sh new file mode 100755 index 0000000..490b63a --- /dev/null +++ b/ansible-playbook.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2022 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## + +if command -v "$(cat /tmp/.ansible_venv)/bin/ansible-playbook" &> /dev/null; then + source "$(cat /tmp/.ansible_venv)/bin/activate" && ANSIBLE_FORCE_COLOR=1 \ + PYTHONUNBUFFERED=1 "$(cat /tmp/.ansible_venv)/bin/ansible-playbook" "$@" +elif command -v "$(which ansible-playbook)"; then + "$(which ansible-playbook)" "$@" +else + echo "ERROR: ansible-playbook not found" + exit +fi diff --git a/docs/requirements.rst b/docs/requirements.rst index 18d62f9..e0f42de 100644 --- a/docs/requirements.rst +++ b/docs/requirements.rst @@ -2,14 +2,13 @@ Requirements ############ -* Ansible 2.4.1 or later -* Packer 1.3.2 or later +* Ansible 2.9.27 or later +* Packer 1.8.2 or later -Install Ansible via pip in a virtualenv if the version is not available via -your local package manager. +Install Ansible via pip in a virtualenv to build images. .. code-block:: bash - virtualenv ansible - source ansible/bin/activate - pip install ansible~=2.4.1 + virtualenv -p $(which python3) ~/venv/.ansible + source ~/venv/.ansible/bin/activate + pip3 install ansible~=2.9.27 diff --git a/docs/update-images.rst b/docs/update-images.rst index 6cf9a2d..7b30d17 100644 --- a/docs/update-images.rst +++ b/docs/update-images.rst @@ -10,8 +10,8 @@ OpenStack cloud. .. code-block:: bash - pip install lftools[openstack] - yum/apt install qemu-img + pip install lftools[openstack] + yum/apt install qemu-img 2. Fetch the image file in .img format diff --git a/releasenotes/notes/get-ansible-from-pypi-702606c724a84d26.yaml b/releasenotes/notes/get-ansible-from-pypi-702606c724a84d26.yaml new file mode 100644 index 0000000..de499f5 --- /dev/null +++ b/releasenotes/notes/get-ansible-from-pypi-702606c724a84d26.yaml @@ -0,0 +1,14 @@ +--- +prelude: > + Install ansible and ansible-playbook using PyPI. +issues: + - | + Error: + Problem: package ansible-5.4.0-3.el8.noarch requires + (ansible-core >= 2.12.2 with ansible-core < 2.13), but none + of the providers can be installed +fixes: + - | + Install ansible through system packages causes dependencies + conflicts on CentOS 8 platform therefore update packer + templates to use ansible provisioner created through venv. diff --git a/templates/builder-aws.json b/templates/builder-aws.json index f5a0f01..b7d7c60 100644 --- a/templates/builder-aws.json +++ b/templates/builder-aws.json @@ -58,6 +58,7 @@ { "type": "ansible", "user": "{{user `ssh_user`}}", + "command": "./common-packer/ansible-playbook.sh", "playbook_file": "provision/local-builder.yaml", "ansible_env_vars": [ "ANSIBLE_NOCOWS=1", diff --git a/templates/builder.json b/templates/builder.json index 0fa217d..1bc82f5 100644 --- a/templates/builder.json +++ b/templates/builder.json @@ -55,6 +55,7 @@ }, { "type": "ansible", + "command": "./common-packer/ansible-playbook.sh", "playbook_file": "provision/local-builder.yaml", "ansible_env_vars": [ "ANSIBLE_NOCOWS=1", diff --git a/templates/docker-aws.json b/templates/docker-aws.json index 831605d..26673ac 100644 --- a/templates/docker-aws.json +++ b/templates/docker-aws.json @@ -58,6 +58,7 @@ { "type": "ansible", "user": "{{user `ssh_user`}}", + "command": "./common-packer/ansible-playbook.sh", "playbook_file": "provision/local-docker.yaml", "ansible_env_vars": [ "ANSIBLE_NOCOWS=1", diff --git a/templates/docker.json b/templates/docker.json index c4699b0..1b57d57 100644 --- a/templates/docker.json +++ b/templates/docker.json @@ -55,6 +55,7 @@ }, { "type": "ansible", + "command": "./common-packer/ansible-playbook.sh", "playbook_file": "provision/local-docker.yaml", "ansible_env_vars": [ "ANSIBLE_NOCOWS=1",