Packer for azurerm: Packer variables not propogating in ansible-local provisioner

9 views
Skip to first unread message

siddhesh4...@gmail.com

unread,
May 22, 2018, 10:10:46 AM5/22/18
to Packer
I am having a packer code that creates an image on azure. I am using ansible-local provisioner for installing the required tools. I execute the below command

packer build -force -var azure_subscription_id=**** -var azure_tennant_id=**** -var azure_application_id=**** -var azure_application_password=**** -var nexus_user=**** -var nexus_password=**** build_packer_azure_image.json

However, the ansible local provisioner executes the below comaand as a part of packer provisioner. I need two variables nexus_username and nexus_password to inherit the values from packer command above.

cd /tmp/packer-provisioner-ansible-local/5b04201f-b988-90e6-b769-24822ffc5333 && ANSIBLE_FORCE_COLOR=1 PYTHONUNBUFFERED=1 ansible-playbook /tmp/packer-provisioner-ansible-local/5b04201f-b988-90e6-b769-24822ffc5333/provision.yml --extra-vars "packer_build_name=azure-arm packer_builder_type=azure-arm packer_http_addr=" --extra-vars 'nexus_username= nexus_password=' -c local -i /tmp/packer-provisioner-ansible-local/5b04201f-b988-90e6-b769-24822ffc5333/packer-provisioner-ansible-local158977121

As it can be seen, the variables are not getting populated. I am placing the sample code snippets for reference in the packer file for reference.

Packer variables configuration:
-------------------------------
{
"variables": {
    "azure_subscription_id": "{{env `azure_subscription_id`}}",
    "azure_tennant_id": "{{env `azure_tennant_id`}}",
    "azure_application_id": "{{env `azure_application_id`}}",
    "azure_application_password": "{{env `azure_application_password`}}",
    "ansible_nexus_user": "{{env `nexus_user`}}",
    "ansible_nexus_password": "{{env `nexus_password`}}"
}

Packer provisioner Configuration:
--------------------------------
"provisioners": [
    {
    "type": "shell",
    "scripts": [
         "../scripts/install_ansible.sh"
      ]
    },
    {
    "type": "ansible-local",
    "playbook_dir": "../workstation-playbook",
    "playbook_file": "../workstation-playbook/provision.yml",
    "extra_arguments": [ "--extra-vars 'nexus_username={{user `ansible_nexus_user`}} nexus_password={{user `ansible_nexus_password`}}'" ]
    },
    {
     "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
     "inline": [
       "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
     ],
     "inline_shebang": "/bin/sh -x",
     "type": "shell"
   }]
}

Please help me resolving the issue.
Reply all
Reply to author
Forward
0 new messages