diff --git a/playbooks/common-tasks/package-cache-proxy.yml b/playbooks/common-tasks/package-cache-proxy.yml index 335c8319df..f8e9cabff8 100644 --- a/playbooks/common-tasks/package-cache-proxy.yml +++ b/playbooks/common-tasks/package-cache-proxy.yml @@ -13,11 +13,28 @@ # 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" + register: proxy_check + failed_when: false + - name: Drop apt package manager proxy copy: content: 'Acquire::http { Proxy "{{ repo_pkg_cache_url }}"; };' dest: "/etc/apt/apt.conf.d/00apt-cacher-proxy" when: + - proxy_check.status == 200 + - ansible_os_family == 'Debian' + - repo_pkg_cache_enabled | bool + +- name: Remove apt package manager proxy + file: + dest: "/etc/apt/apt.conf.d/00apt-cacher-proxy" + state: "absent" + when: + - proxy_check.status != 200 - ansible_os_family == 'Debian' - repo_pkg_cache_enabled | bool @@ -25,6 +42,8 @@ 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 +