github.phpd.cn/hashicorp/packer@v1.3.2/test/provisioner_ansible.bats (about)

     1  #!/usr/bin/env bats
     2  #
     3  # This tests the ansible provisioner on Google Cloud Provider (i.e.
     4  # googlecompute). The teardown function will delete any images with the text
     5  # "packerbats" within the name.
     6  
     7  load test_helper
     8  fixtures provisioner-ansible
     9  
    10  # Required parameters
    11  : ${GC_ACCOUNT_FILE:?}
    12  : ${GC_PROJECT_ID:?}
    13  command -v gcloud >/dev/null 2>&1 || {
    14      echo "'gcloud' must be installed" >&2
    15      exit 1
    16  }
    17  
    18  USER_VARS="${USER_VARS} -var account_file=${GC_ACCOUNT_FILE}"
    19  USER_VARS="${USER_VARS} -var project_id=${GC_PROJECT_ID}"
    20  
    21  # This tests if GCE has an image that contains the given parameter.
    22  gc_has_image() {
    23      gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \
    24          | grep $1 | wc -l
    25  }
    26  
    27  setup(){
    28      rm -f $FIXTURE_ROOT/ansible-test-id
    29      rm -f $FIXTURE_ROOT/ansible-server.key
    30      ssh-keygen -N "" -f $FIXTURE_ROOT/ansible-test-id
    31      ssh-keygen -N "" -f $FIXTURE_ROOT/ansible-server.key
    32  }
    33  
    34  teardown() {
    35      gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \
    36          | grep packerbats \
    37          | xargs -n1 gcloud compute --project=${GC_PROJECT_ID} images delete
    38  
    39      rm -f $FIXTURE_ROOT/ansible-test-id
    40      rm -f $FIXTURE_ROOT/ansible-test-id.pub
    41      rm -f $FIXTURE_ROOT/ansible-server.key
    42      rm -f $FIXTURE_ROOT/ansible-server.key.pub
    43      rm -rf $FIXTURE_ROOT/fetched-dir
    44  }
    45  
    46  @test "ansible provisioner: build docker.json" {
    47      cd $FIXTURE_ROOT
    48      run packer build ${USER_VARS} $FIXTURE_ROOT/docker.json
    49      [ "$status" -eq 0 ]
    50      diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null
    51  }
    52  @test "ansible provisioner: build minimal.json" {
    53      cd $FIXTURE_ROOT
    54      run packer build ${USER_VARS} $FIXTURE_ROOT/minimal.json
    55      [ "$status" -eq 0 ]
    56      [ "$(gc_has_image "packerbats-minimal")" -eq 1 ]
    57      diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null
    58  }
    59  
    60  @test "ansible provisioner: build all_options.json" {
    61      cd $FIXTURE_ROOT
    62      run packer build ${USER_VARS} $FIXTURE_ROOT/all_options.json
    63      [ "$status" -eq 0 ]
    64      [ "$(gc_has_image "packerbats-alloptions")" -eq 1 ]
    65      diff -r dir fetched-dir/packer-test/tmp/remote-dir > /dev/null
    66  }
    67  
    68  @test "ansible provisioner: build scp.json" {
    69      cd $FIXTURE_ROOT
    70      run packer build ${USER_VARS} $FIXTURE_ROOT/scp.json
    71      [ "$status" -eq 0 ]
    72      [ "$(gc_has_image "packerbats-scp")" -eq 1 ]
    73      diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null
    74  }
    75  
    76  @test "ansible provisioner: build scp-to-sftp.json" {
    77      cd $FIXTURE_ROOT
    78      run packer build ${USER_VARS} $FIXTURE_ROOT/scp-to-sftp.json
    79      [ "$status" -eq 0 ]
    80      [ "$(gc_has_image "packerbats-scp-to-sftp")" -eq 1 ]
    81      diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null
    82  }
    83  
    84  @test "ansible provisioner: build sftp.json" {
    85      cd $FIXTURE_ROOT
    86      run packer build ${USER_VARS} $FIXTURE_ROOT/sftp.json
    87      [ "$status" -eq 0 ]
    88      [ "$(gc_has_image "packerbats-sftp")" -eq 1 ]
    89      diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null
    90  }
    91  
    92  @test "ansible provisioner: build winrm.json" {
    93      cd $FIXTURE_ROOT
    94      run packer build ${USER_VARS} $FIXTURE_ROOT/winrm.json
    95      [ "$status" -eq 0 ]
    96      [ "$(gc_has_image "packerbats-winrm")" -eq 1 ]
    97      echo "packer does not support downloading files from download, skipping verification"
    98      #diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null
    99  }