All Projects → nir0s → python-packer

nir0s / python-packer

Licence: Apache-2.0 License
A Packer interface for Python

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to python-packer

packer.py
use python to run hashicorp packer cli commands
Stars: ✭ 21 (-4.55%)
Mutual labels:  packer, hashicorp, python-packer
ansible-role-packer-debian
Ansible Role - Packer Debian/Ubuntu Configuration for Vagrant VirtualBox
Stars: ✭ 32 (+45.45%)
Mutual labels:  packer, hashicorp
local-hashicorp-stack
Local Hashicorp Stack for DevOps Development without Hypervisor or Cloud
Stars: ✭ 23 (+4.55%)
Mutual labels:  packer, hashicorp
vim-hcl
Syntax highlighting for HashiCorp Configuration Language (HCL)
Stars: ✭ 83 (+277.27%)
Mutual labels:  packer, hashicorp
Hcloud Okd4
Deploy OKD4 (OpenShift) on Hetzner Cloud
Stars: ✭ 29 (+31.82%)
Mutual labels:  packer, hashicorp
Ansible Role Packer rhel
Ansible Role - Packer RHEL/CentOS Configuration for Vagrant VirtualBox
Stars: ✭ 45 (+104.55%)
Mutual labels:  packer, hashicorp
Packerlicious
use python to make hashicorp packer templates
Stars: ✭ 90 (+309.09%)
Mutual labels:  packer, hashicorp
learn-terraform-provisioning
Companion code repository for learning to provision Terraform instances with Packer & cloud-init
Stars: ✭ 56 (+154.55%)
Mutual labels:  packer, hashicorp
icp-ce-on-linux-containers
Multi node IBM Cloud Private Community Edition 3.2.x w/ Kubernetes 1.13.5 in a Box. Terraform, Packer and BASH based Infrastructure as Code script sets up a multi node LXD cluster, installs ICP-CE and clis on a metal or VM Ubuntu 18.04 host.
Stars: ✭ 52 (+136.36%)
Mutual labels:  packer, hashicorp
terraform-google-nomad
📗 Terraform Module for Nomad clusters with Consul on GCP
Stars: ✭ 63 (+186.36%)
Mutual labels:  packer
waypoint-plugin-examples
An example repository that demonstrates how to create and run an external Waypoint plugin
Stars: ✭ 16 (-27.27%)
Mutual labels:  hashicorp
PyPackerDetect
A malware dataset curation tool which helps identify packed samples.
Stars: ✭ 27 (+22.73%)
Mutual labels:  packer
insaneworks-packer-template
CentOS 7-8 8Stream / AlmaLinux 8 / FreeBSD 12 - 13 x64 + VirtualBox / VMWare for Packer Template + FreeBSD 13 / AlmaLinux 9 + Parallels
Stars: ✭ 38 (+72.73%)
Mutual labels:  packer
packer-kvm
Create VM templates with Packer for usage with Libvirt/KVM virtualization : CentOS 7, CentOS 8, CentOS 8 Stream, Alma Linux, Rocky Linux, Bionic (Ubuntu 1804), Focal (Ubuntu 2004), Debian 11 (stable), Kali Linux, Fedora 33 and Fedora 34.
Stars: ✭ 99 (+350%)
Mutual labels:  packer
consul-templaterb
consul-template-like with erb (ruby) template expressiveness
Stars: ✭ 65 (+195.45%)
Mutual labels:  hashicorp
php-deb-packager
A PHP library to generate `.deb` packages (Software distribution)
Stars: ✭ 54 (+145.45%)
Mutual labels:  packer
packer-plugin-proxmox
Packer plugin for Proxmox Builder
Stars: ✭ 28 (+27.27%)
Mutual labels:  packer
terraform-provider-filesystem
A @hashicorp Terraform provider for interacting with the filesystem
Stars: ✭ 61 (+177.27%)
Mutual labels:  hashicorp
packer-post-processor-virtualbox-to-hyperv
Packer plugin to create Hyper-V vagrant boxes from VirtualBox artifacts
Stars: ✭ 18 (-18.18%)
Mutual labels:  packer
vault-plugin-secrets-github
Create ephemeral, finely-scoped @github access tokens using @hashicorp Vault.
Stars: ✭ 139 (+531.82%)
Mutual labels:  hashicorp

python-packer

Build Status PyPI PypI

A Python interface for packer.io

Packer version

The interface has been developed vs. Packer v0.7.5.

Installation

You must have Packer installed prior to using this client though as installer class is provided to install packer for you.

 pip install python-packer

 # or, for dev:
 pip install https://github.com/nir0s/python-packer/archive/master.tar.gz

Usage Examples

Packer.build()

import packer

packerfile = 'packer/tests/resources/packerfile.json'
exc = []
only = ['my_first_image', 'my_second_image']
vars = {"variable1": "value1", "variable2": "value2"}
var_file = 'path/to/var/file'
packer_exec_path = '/usr/bin/packer'

p = packer.Packer(packerfile, exc=exc, only=only, vars=vars,
                  var_file=var_file, exec_path=packer_exec_path)
p.build(parallel=True, debug=False, force=False)

Packer.fix()

...

p = packer.Packer(packerfile, ...)
output_file = 'packer/tests/resources/packerfile_fixed.json'
print(p.fix(output_file))

The output_file parameter will write the output of the fix function to a file.

Packer.inspect()

A -machine-readable (mrf) argument is provided.

If the mrf argument is set to True, the output will be parsed and an object containing the parsed output will be exposed as a dictionary containing the components:

...

p = packer.Packer(packerfile, ...)
result = p.inspect(mrf=True)
print(result.parsed_output)
# print(result.stdout) can also be used here

# output:
"variables": [
  {
    "name": "aws_access_key",
    "value": "{{env `AWS_ACCESS_KEY_ID`}}"
  },
  {
    "name": "aws_secret_key",
    "value": "{{env `AWS_ACCESS_KEY`}}"
  }
],
"provisioners": [
  {
    "type": "shell"
  }
],
"builders": [
  {
    "type": "amazon-ebs",
    "name": "amazon"
  }
]

If the mrf argument is set to False, the output will not be parsed but rather returned as is:

...

p = packer.Packer(packerfile, ...)
result = p.inspect(mrf=True)
print(result.stdout)

# output:
Optional variables and their defaults:

  aws_access_key          = {{env `AWS_ACCESS_KEY_ID`}}
  aws_secret_key          = {{env `AWS_ACCESS_KEY`}}

Builders:

  amazon                   (amazon-ebs)

Provisioners:

  shell

...

Packer.push()

You must be logged into Atlas to use the push function:

...

p = packer.Packer(packerfile, ...)
atlas_token = 'oi21mok3mwqtk31om51o2joj213m1oo1i23n1o2'
p.push(create=True, token=atlas_token)

Packer.validate()

...

p = packer.Packer(packerfile, ...)
p.validate(syntax_only=False)

Packer.version()

...

p = packer.Packer(packerfile, ...)
print(p.version())

PackerInstaller.install()

This installs packer to packer_path using the installer_path and verifies that the installation was successful.

packer_path = '/usr/bin/'
installer_path = 'Downloads/packer_0.7.5_linux_amd64.zip'

p = packer.Installer(packer_path, installer_path)
p.install()

Shell Interaction

The sh Python module is used to execute Packer. As such, return values from all functional methods (validate, build, etc..) other than the version method will return an sh execution object. This is meant for you to be able to read stdout, stderr, exit codes and more after executing the commands. With the progression of python-packer less abstract objects will return and more concise return values will be provided.

Additionally, to verify that all errors return with as much info as possible, error handling is done gently. Most errors will raise an sh exception so that you're able to interact with them. Again, as this module progresses, these exceptions will be handled properly.

Testing

Please contribute. Currently tests are not really developed.

git clone [email protected]:nir0s/python-packer.git
cd python-packer
pip install tox
tox

Contributions..

..are always welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].