openstack-ansible/playbooks/common-tasks/package-cache-proxy.yml
Jesse Pretorius 1d731cdd89 Ensure package cache is updated appropriately
When the repo container is removed, the apt cache config
is still in place and causes problems. This is due to the
tasks running to remove the cache configuration not
executing early enough in the deployment.

This patch re-orders the tasks so that the removal can
be done and the cache is updated afterwards to confirm
a working state.

It also makes the configuration happen on all hosts, then
all containers, at the right timings to ensure that if the
container is removed, the proxy config will also be removed
automatically.

Change-Id: I0d1bf9617594d9a5c7c2ea3335c80cc2478df985
2018-03-15 18:56:18 +00:00

87 lines
2.5 KiB
YAML

---
# Copyright 2016, Logan Vig <logan2211@gmail.com>
#
# 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.
- name: test proxy URL for connectivity
uri:
url: "{{ repo_pkg_cache_url }}/acng-report.html"
method: "HEAD"
timeout: 3
register: proxy_check
failed_when: false
tags:
- common-proxy
- name: Add apt package manager proxy
copy:
content: 'Acquire::http { Proxy "{{ repo_pkg_cache_url }}"; };'
dest: "/etc/apt/apt.conf.d/00apt-cacher-proxy"
register: _apt_proxy_added
when:
- repo_pkg_cache_enabled | bool
- proxy_check.status == 200
- ansible_os_family == 'Debian'
tags:
- common-proxy
- name: Remove apt package manager proxy
file:
dest: "/etc/apt/apt.conf.d/00apt-cacher-proxy"
state: "absent"
register: _apt_proxy_removed
when:
- repo_pkg_cache_enabled | bool
- proxy_check.status != 200
- ansible_os_family == 'Debian'
tags:
- common-proxy
- name: Update apt when proxy is added/removed
apt:
update_cache: yes
retries: 5
delay: 2
when:
- (_apt_proxy_added is mapping and _apt_proxy_added | changed) or
(_apt_proxy_removed is mapping and _apt_proxy_removed | changed)
tags:
- common-proxy
# NOTE(mhayden): We always deploy the proxy configuration for yum on CentOS
# even if dnf is present.
- name: Deploy yum package manager proxy
lineinfile:
line: 'proxy={{ repo_pkg_cache_url }}'
dest: "/etc/yum.conf"
state: "{{ (proxy_check.status == 200) | ternary('present', 'absent') }}"
when:
- ansible_os_family == 'RedHat'
- repo_pkg_cache_enabled | bool
tags:
- common-proxy
# NOTE(mhayden): If dnf and yum are installed on CentOS, we need to configure
# a proxy for dnf as well.
- name: Deploy dnf package manager proxy
lineinfile:
line: 'proxy={{ repo_pkg_cache_url }}'
dest: "/etc/dnf/dnf.conf"
state: "{{ (proxy_check.status == 200) | ternary('present', 'absent') }}"
when:
- ansible_os_family == 'RedHat'
- ansible_pkg_mgr == 'dnf'
- repo_pkg_cache_enabled | bool
tags:
- common-proxy