Run python script in shell-local

35 views
Skip to first unread message

Ibrahim Buamod

unread,
Jan 9, 2019, 11:34:25 AM1/9/19
to Packer
run python script in shell-local


"provisioners": [
    {
      "type": "shell-local",
      "environment_vars": ["VM_NAME={{user `Name`}}"],
      "execute_command": ["bash", "-c", "{{.Vars}} {{.Script}}"],
      "script": "./abc.py"
    }

Rickard von Essen

unread,
Jan 9, 2019, 11:43:11 AM1/9/19
to packe...@googlegroups.com
Is that a question? 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/d4b1d147-50f2-4c23-a6df-9a128ff3f637%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ibrahim Buamod

unread,
Jan 9, 2019, 11:44:51 AM1/9/19
to Packer
Yes .. sorry for the poor presentation 

Ibrahim Buamod

unread,
Jan 9, 2019, 11:48:56 AM1/9/19
to Packer
It is a question ? how can I run a python script locally 

Rickard von Essen

unread,
Jan 9, 2019, 12:01:00 PM1/9/19
to packe...@googlegroups.com
That should work, assuming your python script is executable and have a proper shebang.

Megan Marsh

unread,
Jan 9, 2019, 12:21:16 PM1/9/19
to packe...@googlegroups.com
You can also use python in your execute_command; the example below works on my mac; python is in my path and the script "hello.py" is in my working directory

{
    "builders": [
      {
        "type":         "null",
        "communicator": "none"
      }
    ],
    "provisioners": [
      {
          "type": "shell-local",
          "script": "hello.py",
          "execute_command": ["python", "{{.Script}}"]
      }
    ]
}

Here's the command and output from the above example: 

$ packer build shell_local_python.json
null output will be in this color.

==> null: Running local shell script: hello.py
    null: Hello, world!
Build 'null' finished.

==> Builds finished. The artifacts of successful builds are:
--> null: Did not export anything. This is the null builder

Megan Marsh

unread,
Jan 9, 2019, 12:52:16 PM1/9/19
to packe...@googlegroups.com
I think this is a pretty useful question so I've made a PR adding docs for how to do this (including env vars!) here: https://github.com/hashicorp/packer/pull/7181/files
Message has been deleted

Ibrahim Buamod

unread,
Jan 9, 2019, 1:45:36 PM1/9/19
to Packer
So would this be my first contribution to packer :D

Megan Marsh

unread,
Jan 9, 2019, 1:46:56 PM1/9/19
to packe...@googlegroups.com
:D 
Reply all
Reply to author
Forward
0 new messages