@@ -20,35 +20,49 @@ You must have Packer installed prior to using this client (DUH!)
2020 pip install https://github.com/nir0s/python-packer/archive/master.tar.gz
2121```
2222
23- ## Usage Example
23+ ## Usage Examples
24+
25+ ### [ Packer.build()] ( https://www.packer.io/docs/command-line/build.html )
2426
2527``` python
2628import packer
2729
2830packerfile = ' packer/tests/resources/packerfile.json'
29- output_file = ' packer/tests/resources/packerfile_fixed.json'
30- atlas_token = ' oi21mok3mwqtk31om51o2joj213m1oo1i23n1o2'
31- packer_exec_path = ' /usr/bin/packer'
3231exc = []
3332only = [' my_first_image' , ' my_second_image' ]
3433vars = {" variable1" : " value1" , " variable2" : " value2" }
3534vars_file = ' path/to/vars/file'
35+ packer_exec_path = ' /usr/bin/packer'
3636
3737p = packer.Packer(packerfile, exc = exc, only = only, vars = vars ,
3838 vars_file = vars_file, exec_path = packer_exec_path)
39- print (p.version()) # `packer version`
40- p.validate(syntax_only = False ) # `packer validates`
41- print (p.fix(output_file)) # `packer fix`
42- result = p.inspect() # `packer inspect`
43- print (result.parsed_output)
44- p.build(parallel = True , debug = False , force = False ) # `packer build`
45- # if you're logged into Atlas, you can also:
46- p.push(create = True , token = atlas_token) # `packer push`
39+ p.build(parallel = True , debug = False , force = False )
4740```
4841
49- The ` inspect ` method will return a dictionary containing the components:
42+
43+ ### [ Packer.fix()] ( https://www.packer.io/docs/command-line/fix.html )
5044
5145``` python
46+ ...
47+
48+ output_file = ' packer/tests/resources/packerfile_fixed.json'
49+ print (p.fix(output_file))
50+ ```
51+
52+ The ` output_file ` parameter will write the output of the ` fix ` function to a file.
53+
54+
55+ ### [ Packer.inspect()] ( https://www.packer.io/docs/command-line/inspect.html )
56+
57+ If the ` mrf ` argument is set to ` True ` , the output will be parsed and returned as a dictionary containing the components:
58+
59+ ``` python
60+ ...
61+
62+ result = p.inspect(mrf = True )
63+ print (result.parsed_output)
64+
65+ # output:
5266" variables" : [
5367 {
5468 " name" : " aws_access_key" ,
@@ -72,6 +86,60 @@ The `inspect` method will return a dictionary containing the components:
7286]
7387```
7488
89+ If the ` mrf ` argument is set to ` False ` , the output will not be parsed but rather returned as is:
90+
91+ ``` python
92+ ...
93+
94+ result = p.inspect(mrf = True )
95+ print (result.stdout)
96+
97+ # output:
98+ Optional variables and their defaults:
99+
100+ aws_access_key = {{env `AWS_ACCESS_KEY_ID ` }}
101+ aws_secret_key = {{env `AWS_ACCESS_KEY ` }}
102+
103+ Builders:
104+
105+ amazon (amazon- ebs)
106+
107+ Provisioners:
108+
109+ shell
110+
111+ ...
112+
113+ ```
114+
115+
116+ ### [ Packer.push()] ( https://www.packer.io/docs/command-line/push.html )
117+
118+ You must be logged into Atlas to use the ` push ` function:
119+
120+ ``` python
121+ ...
122+
123+ atlas_token = ' oi21mok3mwqtk31om51o2joj213m1oo1i23n1o2'
124+ p.push(create = True , token = atlas_token)
125+ ```
126+
127+ ### [ Packer.validate()] ( https://www.packer.io/docs/command-line/validate.html )
128+
129+ ``` python
130+ ...
131+
132+ p.validate(syntax_only = False )
133+ ```
134+
135+ ### Packer.version()
136+
137+ ``` python
138+ ...
139+
140+ print (p.version())
141+ ```
142+
75143## Shell Interaction
76144
77145The [ sh] ( http://amoffat.github.io/sh/ ) Python module is used to execute Packer.
0 commit comments