Temporary inventory file not created by Packer

My Packer Version 1.6.0

Hello,

The official docs says, if the inventory_file string is not specified, Packer will create a temp inventory file. But in my case its not creating any file and it fails. Could you please clarify me what was wrong here?

Provisioner code block:

         "provisioners": [
            {
              "type": "ansible",
              "user": "user1",
              "use_proxy": "false",
              "extra_arguments": [ "--extra-vars", "account_file={{user `account_file`}} nexus_pwd={{user `nexus_pwd`}} nexus_user={{user `nexus_user`}}" ],
              "ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False" ],
              "playbook_file": "/home/user1/test.yml"
            }
          ]

Output:

==> googlecompute: Executing Ansible: ansible-playbook -e packer_build_name=googlecompute -e packer_builder_type=googlecompute -e packer_http_addr=ERR_HTTP_ADDR_NOT_IMPLEMENTED_BY_BUILDER --ssh-extra-args '-o IdentitiesOnly=yes' --extra-vars account_file=/opt/key.json nexus_pwd=xxxx nexus_user=xxxx -e ansible_ssh_private_key_file=/tmp/ansible-key210193160 -i /tmp/packer-provisioner-ansible452653767 /home/user1/test.yml
    googlecompute:  [WARNING]: Could not match supplied host pattern, ignoring: ihs
    googlecompute:
    googlecompute: PLAY [Ansible Playbook to install Test YAML] *************************
    googlecompute: skipping: no hosts matched
    googlecompute:
    googlecompute: PLAY RECAP *********************************************************************
    googlecompute:
2020/09/04 16:56:32 [INFO] (telemetry) ending ansible

There is a temporary inventory file being used. See -i /tmp/packer-provisioner-ansible452653767 in your ansible comand. It gets cleaned up at the end of the provisioning run, though. You can set the template option "keep_inventory_file": true to prevent Packer from deleting the file.

But based on a previous comment you’re using an old version of Packer so this probably will not work for you. The keep_inventory_file feature was added around the same time as the use_proxy option.

A lot of work has been done to clean up the ansible provisioner recently because it was unmaintained for a long time. If you can’t upgrade it may just be broken for your use case. In that situation I recommend using the shell-local provisioner to call ansible manually, rather than spending a ton of time trying to get ansible working.