diff --git a/playbooks/unittests/pre.yaml b/playbooks/unittests/pre.yaml index 011865e23..1aca2e62b 100644 --- a/playbooks/unittests/pre.yaml +++ b/playbooks/unittests/pre.yaml @@ -6,6 +6,10 @@ gather_subset: - "!all" roles: + - role: configure-mirrors + # TODO(mordred) When we have site-local variables, these should go there + mirror_host: "mirror.{{ nodepool.region | lower }}.{{ nodepool.provider | lower }}.openstack.org" + mirror_domain: openstack.org - role: validate-host # TODO(mordred) When we have site-local variables, these should go there zuul_traceroute_host: git.openstack.org diff --git a/roles/configure-mirrors/README.rst b/roles/configure-mirrors/README.rst new file mode 100644 index 000000000..4edab2e7a --- /dev/null +++ b/roles/configure-mirrors/README.rst @@ -0,0 +1 @@ +An ansible role to configure mirrors for common services diff --git a/roles/configure-mirrors/defaults/main.yaml b/roles/configure-mirrors/defaults/main.yaml new file mode 100644 index 000000000..9a49f11e8 --- /dev/null +++ b/roles/configure-mirrors/defaults/main.yaml @@ -0,0 +1,2 @@ +mirror_host: mirror.example.org +pypi_mirror: "http://{{ mirror_host }}/pypi/simple" diff --git a/roles/configure-mirrors/files/etc/apt/apt.conf.d/99unauthenticated b/roles/configure-mirrors/files/etc/apt/apt.conf.d/99unauthenticated new file mode 100644 index 000000000..351f64bcb --- /dev/null +++ b/roles/configure-mirrors/files/etc/apt/apt.conf.d/99unauthenticated @@ -0,0 +1,4 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +APT::Get::AllowUnauthenticated "true"; diff --git a/roles/configure-mirrors/tasks/main.yaml b/roles/configure-mirrors/tasks/main.yaml new file mode 100644 index 000000000..2d9f1f79e --- /dev/null +++ b/roles/configure-mirrors/tasks/main.yaml @@ -0,0 +1,2 @@ +- include: mirror.yaml + when: mirror_host is defined diff --git a/roles/configure-mirrors/tasks/mirror.yaml b/roles/configure-mirrors/tasks/mirror.yaml new file mode 100644 index 000000000..1f041e396 --- /dev/null +++ b/roles/configure-mirrors/tasks/mirror.yaml @@ -0,0 +1,27 @@ +- name: Include OS-specific variables + include_vars: "{{ ansible_distribution | lower }}.yaml" + +- name: Install /etc/pip.conf configuration + become: yes + template: + dest: /etc/pip.conf + group: root + mode: 0644 + owner: root + src: etc/pip.conf.j2 + +- name: Install .pydistutils.cfg configuration in homedir + template: + dest: ~/.pydistutils.cfg + mode: 0644 + src: .pydistutils.cfg.j2 + +- name: Setup distro specific packaging mirrors. + include: "packages/{{ ansible_distribution | lower }}.yaml" + +# Make sure OS does not have a stale package cache. +- name: Update apt cache + become: yes + apt: + update_cache: yes + when: ansible_os_family == 'Debian' diff --git a/roles/configure-mirrors/tasks/packages/ubuntu.yaml b/roles/configure-mirrors/tasks/packages/ubuntu.yaml new file mode 100644 index 000000000..5619df5eb --- /dev/null +++ b/roles/configure-mirrors/tasks/packages/ubuntu.yaml @@ -0,0 +1,17 @@ +- name: Install /etc/apt/sources.list + become: yes + template: + dest: /etc/apt/sources.list + group: root + mode: 0644 + owner: root + src: etc/apt/sources.list.j2 + +- name: Install /etc/apt/apt.conf.d/99unauthenticated + become: yes + copy: + dest: /etc/apt/apt.conf.d/99unauthenticated + group: root + mode: 0644 + owner: root + src: etc/apt/apt.conf.d/99unauthenticated diff --git a/roles/configure-mirrors/templates/.pydistutils.cfg.j2 b/roles/configure-mirrors/templates/.pydistutils.cfg.j2 new file mode 100644 index 000000000..a1cdde33c --- /dev/null +++ b/roles/configure-mirrors/templates/.pydistutils.cfg.j2 @@ -0,0 +1,8 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +[easy_install] +index_url = {{ pypi_mirror }} +{% if mirror_domain is defined %} +allow_hosts = *.{{ mirror_domain }} +{% endif %} diff --git a/roles/configure-mirrors/templates/etc/apt/sources.list.j2 b/roles/configure-mirrors/templates/etc/apt/sources.list.j2 new file mode 100644 index 000000000..bf302651c --- /dev/null +++ b/roles/configure-mirrors/templates/etc/apt/sources.list.j2 @@ -0,0 +1,7 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +deb {{ package_mirror }} {{ ansible_distribution_release }} main universe +deb {{ package_mirror }} {{ ansible_distribution_release }}-updates main universe +deb {{ package_mirror }} {{ ansible_distribution_release }}-backports main universe +deb {{ package_mirror }} {{ ansible_distribution_release }}-security main universe diff --git a/roles/configure-mirrors/templates/etc/pip.conf.j2 b/roles/configure-mirrors/templates/etc/pip.conf.j2 new file mode 100644 index 000000000..4f461fc30 --- /dev/null +++ b/roles/configure-mirrors/templates/etc/pip.conf.j2 @@ -0,0 +1,8 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +[global] +timeout = 60 +index-url = {{ pypi_mirror }} +trusted-host = {{ mirror_host }} +extra-index-url = {{ wheel_mirror }} diff --git a/roles/configure-mirrors/vars/ubuntu.yaml b/roles/configure-mirrors/vars/ubuntu.yaml new file mode 100644 index 000000000..f9f204bff --- /dev/null +++ b/roles/configure-mirrors/vars/ubuntu.yaml @@ -0,0 +1,2 @@ +wheel_mirror: "http://{{ mirror_host }}/wheel/{{ ansible_distribution | lower }}-{{ ansible_distribution_version }}-{{ ansible_architecture | lower }}" +package_mirror: "http://{{ mirror_host }}/ubuntu"