From 41a8a96821008ec24dde77d70966fd51eace0f0f Mon Sep 17 00:00:00 2001 From: Artis3n Date: Sat, 5 Sep 2020 16:48:20 -0400 Subject: [PATCH] Added acceptance test for Galaxy Collection install --- .../provisioner-ansible/galaxy-playbook.yml | 33 +++++++++++++++++++ test/fixtures/provisioner-ansible/galaxy.json | 21 ++++++++++++ .../provisioner-ansible/requirements.yml | 2 ++ test/provisioner_ansible.bats | 8 +++++ 4 files changed, 64 insertions(+) create mode 100644 test/fixtures/provisioner-ansible/galaxy-playbook.yml create mode 100644 test/fixtures/provisioner-ansible/galaxy.json create mode 100644 test/fixtures/provisioner-ansible/requirements.yml diff --git a/test/fixtures/provisioner-ansible/galaxy-playbook.yml b/test/fixtures/provisioner-ansible/galaxy-playbook.yml new file mode 100644 index 000000000..b91a3dab4 --- /dev/null +++ b/test/fixtures/provisioner-ansible/galaxy-playbook.yml @@ -0,0 +1,33 @@ +--- +- hosts: default:packer-test + gather_facts: no + collections: + - artis3n.github + tasks: + - name: touch + raw: touch /tmp/ansible-raw-test + - name: raw test + raw: date + - name: command test + command: echo "the command module" + - name: prepare remote directory + command: mkdir /tmp/remote-dir + args: + creates: /tmp/remote-dir + - name: transfer file.txt + copy: src=dir/file.txt dest=/tmp/remote-dir/file.txt + - name: fetch file.text + fetch: src=/tmp/remote-dir/file.txt dest=fetched-dir validate=yes fail_on_missing=yes + - name: copy contents of directory + copy: src=dir/contents-only/ dest=/tmp/remote-dir + - name: fetch contents of directory + fetch: src=/tmp/remote-dir/file.txt dest="fetched-dir/{{ inventory_hostname }}/tmp/remote-dir/contents-only/" flat=yes validate=yes fail_on_missing=yes + - name: copy directory recursively + copy: src=dir/subdir dest=/tmp/remote-dir + - name: fetch recursively copied directory + fetch: src=/tmp/remote-dir/subdir/file.txt dest=fetched-dir validate=yes fail_on_missing=yes + - copy: src=largish-file.txt dest=/tmp/largish-file.txt + - name: test collection - fetch latest repo version + set_fact: + # Ansible will fail if collection is not installed + packer_version: "{{ lookup('artis3n.github.latest_release', 'hashicorp/packer' }}" diff --git a/test/fixtures/provisioner-ansible/galaxy.json b/test/fixtures/provisioner-ansible/galaxy.json new file mode 100644 index 000000000..e09a47cdc --- /dev/null +++ b/test/fixtures/provisioner-ansible/galaxy.json @@ -0,0 +1,21 @@ +{ + "variables": {}, + "provisioners": [ + { + "type": "ansible", + "playbook_file": "./playbook.yml", + "galaxy_file": "./requirements.yml" + } + ], + "builders": [ + { + "type": "googlecompute", + "account_file": "{{user `account_file`}}", + "project_id": "{{user `project_id`}}", + "image_name": "packerbats-galaxy-{{timestamp}}", + "source_image": "debian-8-jessie-v20161027", + "zone": "us-central1-a", + "ssh_username": "debian" + } + ] +} diff --git a/test/fixtures/provisioner-ansible/requirements.yml b/test/fixtures/provisioner-ansible/requirements.yml new file mode 100644 index 000000000..4658d9204 --- /dev/null +++ b/test/fixtures/provisioner-ansible/requirements.yml @@ -0,0 +1,2 @@ +collections: + - name: artis3n.github diff --git a/test/provisioner_ansible.bats b/test/provisioner_ansible.bats index c9dc9abd9..2cc45b522 100755 --- a/test/provisioner_ansible.bats +++ b/test/provisioner_ansible.bats @@ -65,6 +65,14 @@ teardown() { diff -r dir fetched-dir/packer-test/tmp/remote-dir > /dev/null } +@test "ansible provisioner: build galaxy.json" { + cd $FIXTURE_ROOT + run packer build ${USER_VARS} $FIXTURE_ROOT/galaxy.json + [ "$status" -eq 0 ] + [ "$(gc_has_image "packerbats-galaxy")" -eq 1 ] + diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null +} + @test "ansible provisioner: build scp.json" { cd $FIXTURE_ROOT run packer build ${USER_VARS} $FIXTURE_ROOT/scp.json