Skip to content

Instantly share code, notes, and snippets.

@xinau
Created April 13, 2020 21:17
Show Gist options
  • Save xinau/d33dc377d2ad5f9718baf26d35b8fb41 to your computer and use it in GitHub Desktop.
Save xinau/d33dc377d2ad5f9718baf26d35b8fb41 to your computer and use it in GitHub Desktop.
Building docker images using packer and ansible
{
"variables": {
"host": "default",
},
"builders": [
{
"type": "docker",
"image": "debian:9.6",
"commit": true,
"run_command": [
"-d",
"-i",
"-t",
"--name",
"{{user `host`}}",
"{{.Image}}",
"/bin/bash"
]
}
],
"provisioners": [
{
"type": "ansible",
"user": "root",
"playbook_file": "./playbook.yml",
"extra_arguments": [
"--extra-vars",
"ansible_host={{user `host`}} ansible_connection=docker"
]
}
]
}
- hosts: all
tasks:
- name: "install python"
raw: "apt-get update && apt-get install -yq python"
- name: "install netcat"
apt:
state: present
update_cache: true
name:
- "netcat"
- name: "remove apt content"
file:
state: absent
path: "/var/lib/apt/lists/"
- name: "remove python"
apt:
autoremove: true
purge: true
name:
- python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment