Controlling with Ansible packer

I wanted to tell ansible with this script that the packer has to activate to generate a packer image file that then talks to proxmox via an API. Below is the ansible script I’m trying with:

  • name: Check and run Packer
    hosts: purple
    tasks:

  • name: Check if test.pkr.hcl exists
    stat:
    path: /home/oxana/packer/project/test.pkr.hcl
    register: file_status

  • name: Run Packer build if file exists
    command: packer build /home/oxana/packer/project/test.pkr.hcl
    when: file_status.stat.exists