update docs for shell provisioner to include hcl examples
This commit is contained in:
parent
7967b788d2
commit
767e2fe06b
@ -24,6 +24,9 @@ Shell](/docs/provisioners/windows-shell) provisioners.
|
|||||||
|
|
||||||
The example below is fully functional.
|
The example below is fully functional.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<Tab heading="JSON">
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
@ -31,6 +34,18 @@ The example below is fully functional.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
<Tab heading="HCL2">
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
provisioner "shell" {
|
||||||
|
inline = ["echo foo"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
## Configuration Reference
|
## Configuration Reference
|
||||||
|
|
||||||
@include 'provisioners/shell-config.mdx'
|
@include 'provisioners/shell-config.mdx'
|
||||||
@ -67,8 +82,9 @@ The example below is fully functional.
|
|||||||
- `EnvVarFile` is the path to the file containing env vars, if
|
- `EnvVarFile` is the path to the file containing env vars, if
|
||||||
`use_env_var_file` is true.
|
`use_env_var_file` is true.
|
||||||
|
|
||||||
- `expect_disconnect` (boolean) - Defaults to `false`. When `true`, allow the server to disconnect from Packer without throwing an error.
|
- `expect_disconnect` (boolean) - Defaults to `false`. When `true`, allow the
|
||||||
A disconnect might happen if you restart the ssh server or reboot the host.
|
server to disconnect from Packer without throwing an error. A disconnect
|
||||||
|
might happen if you restart the ssh server or reboot the host.
|
||||||
|
|
||||||
- `inline_shebang` (string) - The
|
- `inline_shebang` (string) - The
|
||||||
[shebang](https://en.wikipedia.org/wiki/Shebang_%28Unix%29) value to use
|
[shebang](https://en.wikipedia.org/wiki/Shebang_%28Unix%29) value to use
|
||||||
@ -183,6 +199,9 @@ and Packer will start executing the next one before SSH actually quits and the
|
|||||||
machine restarts. For this, put use "pause_before" to make Packer wait before
|
machine restarts. For this, put use "pause_before" to make Packer wait before
|
||||||
executing the next script:
|
executing the next script:
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<Tab heading="JSON">
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
@ -192,6 +211,20 @@ executing the next script:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
<Tab heading="HCL2">
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
provisioner "shell" {
|
||||||
|
script = "script.sh"
|
||||||
|
pause_before = "10s"
|
||||||
|
timeout = "10s"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
Some OS configurations don't properly kill all network connections on reboot,
|
Some OS configurations don't properly kill all network connections on reboot,
|
||||||
causing the provisioner to hang despite a reboot occurring. In this case, make
|
causing the provisioner to hang despite a reboot occurring. In this case, make
|
||||||
sure you shut down the network interfaces on reboot or in your shell script.
|
sure you shut down the network interfaces on reboot or in your shell script.
|
||||||
@ -217,6 +250,9 @@ provisioner](/docs/provisioners/file) (more secure) or using `ssh-keyscan`
|
|||||||
to populate the file (less secure). An example of the latter accessing github
|
to populate the file (less secure). An example of the latter accessing github
|
||||||
would be:
|
would be:
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<Tab heading="JSON">
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
@ -228,6 +264,22 @@ would be:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
<Tab heading="HCL2">
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
provisioner "shell" {
|
||||||
|
inline = [
|
||||||
|
"sudo apt-get install -y git",
|
||||||
|
"ssh-keyscan github.com >> ~/.ssh/known_hosts",
|
||||||
|
"git clone git@github.com:exampleorg/myprivaterepo.git"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
_My shell script doesn't work correctly on Ubuntu_
|
_My shell script doesn't work correctly on Ubuntu_
|
||||||
@ -260,6 +312,9 @@ _My builds don't always work the same_
|
|||||||
can create race conditions. Your first provisioner can tell the machine to
|
can create race conditions. Your first provisioner can tell the machine to
|
||||||
wait until it completely boots.
|
wait until it completely boots.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<Tab heading="JSON">
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
@ -267,32 +322,77 @@ _My builds don't always work the same_
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
<Tab heading="HCL2">
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
provisioner "shell" {
|
||||||
|
inline = ["sleep 10"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
## Quoting Environment Variables
|
## Quoting Environment Variables
|
||||||
|
|
||||||
Packer manages quoting for you, so you should't have to worry about it. Below
|
Packer manages quoting for you, so you should't have to worry about it. Below
|
||||||
is an example of packer template inputs and what you should expect to get out:
|
is an example of packer template inputs and what you should expect to get out:
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<Tab heading="JSON">
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"provisioners": [
|
"provisioners": [
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"environment_vars": ["FOO=foo",
|
"environment_vars": ["FOO=foo",
|
||||||
"BAR=bar's",
|
"BAR=bar's",
|
||||||
"BAZ=baz=baz",
|
"BAZ=baz=baz",
|
||||||
"QUX==qux",
|
"QUX==qux",
|
||||||
"FOOBAR=foo bar",
|
"FOOBAR=foo bar",
|
||||||
"FOOBARBAZ='foo bar baz'",
|
"FOOBARBAZ='foo bar baz'",
|
||||||
"QUX2=\"qux\""],
|
"QUX2=\"qux\""],
|
||||||
"inline": ["echo \"FOO is $FOO\"",
|
"inline": ["echo \"FOO is $FOO\"",
|
||||||
"echo \"BAR is $BAR\"",
|
"echo \"BAR is $BAR\"",
|
||||||
"echo \"BAZ is $BAZ\"",
|
"echo \"BAZ is $BAZ\"",
|
||||||
"echo \"QUX is $QUX\"",
|
"echo \"QUX is $QUX\"",
|
||||||
"echo \"FOOBAR is $FOOBAR\"",
|
"echo \"FOOBAR is $FOOBAR\"",
|
||||||
"echo \"FOOBARBAZ is $FOOBARBAZ\"",
|
"echo \"FOOBARBAZ is $FOOBARBAZ\"",
|
||||||
"echo \"QUX2 is $QUX2\""]
|
"echo \"QUX2 is $QUX2\""]
|
||||||
}
|
}
|
||||||
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
<Tab heading="HCL2">
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
provisioner "shell" {
|
||||||
|
environment_vars = [
|
||||||
|
"FOO=foo",
|
||||||
|
"BAR=bar's",
|
||||||
|
"BAZ=baz=baz",
|
||||||
|
"QUX==qux",
|
||||||
|
"FOOBAR=foo bar",
|
||||||
|
"FOOBARBAZ='foo bar baz'",
|
||||||
|
"QUX2=\"qux\""
|
||||||
|
]
|
||||||
|
inline = [
|
||||||
|
"echo \"FOO is $FOO\"",
|
||||||
|
"echo \"BAR is $BAR\"",
|
||||||
|
"echo \"BAZ is $BAZ\"",
|
||||||
|
"echo \"QUX is $QUX\"",
|
||||||
|
"echo \"FOOBAR is $FOOBAR\"",
|
||||||
|
"echo \"FOOBARBAZ is $FOOBARBAZ\"",
|
||||||
|
"echo \"QUX2 is $QUX2\""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user