How to copy local vm files to azure builder vm in packer build

234 Views Asked by At

I am new to Packer + Ansible combination example. Below is my provisioner which is calling ansible yml file using Azure builder,

"provisioners": [
        {
            "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
            "inline": [
                "sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E '%{rhel}').noarch.rpm",
                "sudo yum -y install ansible"
            ],
            "inline_shebang": "/bin/sh -x",
            "type": "shell"
        },
        {
            "type": "ansible-local",
            "playbook_file": "/tmp/app.yml"
        }
    ]

In my app.yml, I want to copy my script to temporary vm (pkr* ) that gets created at the time of packer build run. So /tmp/script.sh will be executed. However I am not getting exact module to be used to copy file from local(/tmp/script.sh) to packer builder vm.

app.yml

- hosts: localhost
  tasks:
  - name: copy script from local to vm
    ansible.builtin.template:
      src: /tmp/script.sh
      dest: /tmp/
  - name: validate copied files
    command: ls /tmp
  - copy:
      src: /tmp/script.sh
      dest: /tmp/
  - command: ls /tmp/
  - script: /tmp/script.sh

Error :

azure-arm: TASK [copy script from local to vm] ****************************************
    azure-arm: fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Could not find or access '/tmp/script.sh' on the Ansible Controller.\nIf you are usin
g a module and expect the file to exist on the remote, see the remote_src option"}

I have tried both copy and ansible.builtin.template modules, but no luck.

0

There are 0 best solutions below