Packer shell Provisioner: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=External= * https://www.packer.io/docs/provisioners/shell.htm =Internal= * Packer Concepts") |
(→script) |
||
(11 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
* [[Packer Concepts#shell|Packer Concepts]] | * [[Packer Concepts#shell|Packer Concepts]] | ||
=Overview= | |||
=shell Provisioner Types= | |||
==inline== | |||
<syntaxhighlight lang='json'> | |||
{ | |||
... | |||
"provisioners": [ | |||
{ | |||
"type": "shell", | |||
"inline": ["sudo yum install ansible"] | |||
}, | |||
... | |||
] | |||
} | |||
</syntaxhighlight> | |||
==script== | |||
<syntaxhighlight lang='json'> | |||
{ | |||
... | |||
"provisioners": [ | |||
{ | |||
"type": "shell", | |||
"only": [ | |||
"my-builder" | |||
], | |||
"environment_vars": [ | |||
"SOMETHING={{ user `something` }}" | |||
], | |||
"execute_command": "echo '' | {{ .Vars }} sudo -S -E -u root '{{ .Path }}'", | |||
"script": "scripts/something.sh" | |||
}, | |||
... | |||
] | |||
} | |||
</syntaxhighlight> | |||
While executing the script, its stdout will be relayed to the controlling terminal. However, the name of the script will not match the name of the local source script. Assuming that our script is ./scripts/something.sh, if we echo "executing $0" from it will get something similar to: | |||
<syntaxhighlight lang='text'> | |||
... | |||
infra-worker: executing /tmp/script_233.sh | |||
... | |||
</syntaxhighlight> | |||
==scripts== | |||
<syntaxhighlight lang='json'> | |||
{ | |||
... | |||
"provisioners": [ | |||
{ | |||
"type": "shell", | |||
"only": [ | |||
"my-builder" | |||
], | |||
"environment_vars": [ | |||
"SOMETHING={{ user `something` }}" | |||
], | |||
"execute_command": "echo '' | {{ .Vars }} sudo -S -E -u root '{{ .Path }}'", | |||
"scripts": [ | |||
"scripts/something.sh", | |||
"scripts/something-else.sh", | |||
] | |||
}, | |||
... | |||
] | |||
} | |||
</syntaxhighlight> | |||
=Parameters= | |||
====execute_command==== | |||
A String that specifies the command to use to execute the script. The default value, unless specified, is: | |||
chmod +x {{ [[Writing_Packer_Templates#.Path|.Path]] }}; {{ [[Writing_Packer_Templates#.Vars|.Vars]] }} {{ [[Writing_Packer_Templates#.Path|.Path]] }} |
Latest revision as of 17:55, 15 November 2019
External
Internal
Overview
shell Provisioner Types
inline
{
...
"provisioners": [
{
"type": "shell",
"inline": ["sudo yum install ansible"]
},
...
]
}
script
{
...
"provisioners": [
{
"type": "shell",
"only": [
"my-builder"
],
"environment_vars": [
"SOMETHING={{ user `something` }}"
],
"execute_command": "echo '' | {{ .Vars }} sudo -S -E -u root '{{ .Path }}'",
"script": "scripts/something.sh"
},
...
]
}
While executing the script, its stdout will be relayed to the controlling terminal. However, the name of the script will not match the name of the local source script. Assuming that our script is ./scripts/something.sh, if we echo "executing $0" from it will get something similar to:
...
infra-worker: executing /tmp/script_233.sh
...
scripts
{
...
"provisioners": [
{
"type": "shell",
"only": [
"my-builder"
],
"environment_vars": [
"SOMETHING={{ user `something` }}"
],
"execute_command": "echo '' | {{ .Vars }} sudo -S -E -u root '{{ .Path }}'",
"scripts": [
"scripts/something.sh",
"scripts/something-else.sh",
]
},
...
]
}
Parameters
execute_command
A String that specifies the command to use to execute the script. The default value, unless specified, is:
chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}