Created
August 24, 2022 08:45
-
-
Save fourdollars/a3cd1b34aa9d99665d979e66a5c6716d to your computer and use it in GitHub Desktop.
sudo packer build docker.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"variables": { | |
"ansible_host": "default", | |
"ansible_connection": "docker" | |
}, | |
"builders": [ | |
{ | |
"type": "docker", | |
"image": "centos:7", | |
"commit": true, | |
"run_command": [ | |
"-d", | |
"-i", | |
"-t", | |
"--name", | |
"{{user `ansible_host`}}", | |
"{{.Image}}", | |
"/bin/bash" | |
] | |
} | |
], | |
"provisioners": [ | |
{ | |
"type": "ansible", | |
"groups": ["webserver"], | |
"playbook_file": "./webserver.yml", | |
"extra_arguments": [ | |
"--extra-vars", | |
"ansible_host={{user `ansible_host`}} ansible_connection={{user `ansible_connection`}}" | |
] | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: configure webserver | |
hosts: webserver | |
tasks: | |
- name: install Apache | |
yum: | |
name: httpd |
This also works.
{
"variables": {
"ansible_host": "default",
"ansible_connection": "docker"
},
"builders": [
{
"type": "docker",
"image": "centos:7",
"commit": true,
"run_command": [
"-d",
"-i",
"-t",
"--name",
"{{user `ansible_host`}}",
"{{.Image}}",
"/bin/bash"
]
}
],
"provisioners": [
{
"type": "ansible",
"user": "root",
"groups": ["webserver"],
"playbook_file": "./webserver.yml",
"extra_arguments": [
"--extra-vars",
"ansible_host={{user `ansible_host`}} ansible_connection={{user `ansible_connection`}}"
]
}
]
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
packer build docker.json
for the following content works withoutsudo
.