diff --git a/tests/image_prep/_container_setup.yml b/tests/image_prep/_container_setup.yml index 6e1416df..eabd97a8 100644 --- a/tests/image_prep/_container_setup.yml +++ b/tests/image_prep/_container_setup.yml @@ -61,8 +61,11 @@ when: distro == "CentOS" - file: - path: /var/cache/apt + path: "{{item}}" state: absent + with_items: + - /var/cache/apt + - /var/lib/apt when: distro == "Debian" - user: diff --git a/tests/image_prep/_user_accounts.yml b/tests/image_prep/_user_accounts.yml index 1ed2c61d..0167a09f 100644 --- a/tests/image_prep/_user_accounts.yml +++ b/tests/image_prep/_user_accounts.yml @@ -34,6 +34,7 @@ }}" tasks: - name: Disable non-localhost SSH for Mitogen users + when: false blockinfile: path: /etc/ssh/sshd_config block: | diff --git a/tests/image_prep/build_docker_images.py b/tests/image_prep/build_docker_images.py index 8a4161db..44c4e2dd 100755 --- a/tests/image_prep/build_docker_images.py +++ b/tests/image_prep/build_docker_images.py @@ -6,6 +6,7 @@ Build the Docker images used for testing. import commands import os +import tempfile import shlex import subprocess @@ -19,25 +20,36 @@ def sh(s, *args): return shlex.split(s) -for base_image, name in [('debian:stretch', 'debian'), - ('centos:6', 'centos6'), - ('centos:7', 'centos7')]: - args = sh('docker run --rm -it -d %s /bin/bash', base_image) + +label_by_id = {} + +for base_image, label in [('debian:stretch', 'debian'), + ('centos:6', 'centos6'), + ('centos:7', 'centos7')]: + args = sh('docker run --rm -it -d -h mitogen-%s %s /bin/bash', + label, base_image) container_id = subprocess.check_output(args).strip() + label_by_id[container_id] = label + +with tempfile.NamedTemporaryFile() as fp: + fp.write('[all]\n') + for id_, label in label_by_id.items(): + fp.write('%s ansible_host=%s\n' % (label, id_)) + fp.flush() + try: subprocess.check_call( cwd=BASEDIR, - args=sh(''' - ansible-playbook -i %s, -c docker setup.yml -vvv - ''', container_id) + args=sh('ansible-playbook -i %s -c docker setup.yml', fp.name), ) - subprocess.check_call(sh(''' - docker commit - --change 'EXPOSE 22' - --change 'CMD ["/usr/sbin/sshd", "-D"]' - %s - mitogen/%s-test - ''', container_id, name)) + for container_id, label in label_by_id.items(): + subprocess.check_call(sh(''' + docker commit + --change 'EXPOSE 22' + --change 'CMD ["/usr/sbin/sshd", "-D"]' + %s + mitogen/%s-test + ''', container_id, label)) finally: - subprocess.check_call(sh('docker rm -f %s', container_id)) + subprocess.check_call(sh('docker rm -f %s', ' '.join(label_by_id)))