github.com/aspring/packer@v0.8.1-0.20150629211158-9db281ac0f89/website/source/docs/command-line/machine-readable.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Machine-Readable Output - Command-Line"
     4  description: |-
     5    By default, the output of Packer is very human-readable. It uses nice formatting, spacing, and colors in order to make Packer a pleasure to use. However, Packer was built with automation in mind. To that end, Packer supports a fully machine-readable output setting, allowing you to use Packer in automated environments.
     6  ---
     7  
     8  # Machine-Readable Output
     9  
    10  By default, the output of Packer is very human-readable. It uses nice
    11  formatting, spacing, and colors in order to make Packer a pleasure to use.
    12  However, Packer was built with automation in mind. To that end, Packer
    13  supports a fully machine-readable output setting, allowing you to use
    14  Packer in automated environments.
    15  
    16  The machine-readable output format is easy to use and read and was made
    17  with Unix tools in mind, so it is awk/sed/grep/etc. friendly.
    18  
    19  ## Enabling
    20  
    21  The machine-readable output format can be enabled by passing the
    22  `-machine-readable` flag to any Packer command. This immediately enables
    23  all output to become machine-readable on stdout. Logging, if enabled,
    24  continues to appear on stderr. An example of the output is shown
    25  below:
    26  
    27  ```text
    28  $ packer -machine-readable version
    29  1376289459,,version,0.2.4
    30  1376289459,,version-prerelease,
    31  1376289459,,version-commit,eed6ece
    32  1376289459,,ui,say,Packer v0.2.4.dev (eed6ece+CHANGES)
    33  ```
    34  
    35  The format will be covered in more detail later. But as you can see,
    36  the output immediately becomes machine-friendly. Try some other commands
    37  with the `-machine-readable` flag to see!
    38  
    39  ## Format
    40  
    41  The machine readable format is a line-oriented, comma-delimited text
    42  format. This makes it extremely easy to parse using standard Unix tools such
    43  as awk or grep in addition to full programming languages like Ruby or
    44  Python.
    45  
    46  The format is:
    47  
    48  ```text
    49  timestamp,target,type,data...
    50  ```
    51  
    52  Each component is explained below:
    53  
    54  * **timestamp** is a Unix timestamp in UTC of when the message was
    55    printed.
    56  
    57  * **target** is the target of the following output. This is empty if
    58    the message is related to Packer globally. Otherwise, this is generally
    59    a build name so you can relate output to a specific build while parallel
    60    builds are running.
    61  
    62  * **type** is the type of machine-readable message being outputted. There
    63    are a set of standard types which are covered later, but each component
    64    of Packer (builders, provisioners, etc.) may output their own custom types
    65    as well, allowing the machine-readable output to be infinitely flexible.
    66  
    67  * **data** is zero or more comma-seperated values associated with the prior
    68    type. The exact amount and meaning of this data is type-dependent, so you
    69    must read the documentation associated with the type to understand fully.
    70  
    71  Within the format, if data contains a comma, it is replaced with
    72  `%!(PACKER_COMMA)`. This was preferred over an escape character such as
    73  `\'` because it is more friendly to tools like awk.
    74  
    75  Newlines within the format are replaced with their respective standard
    76  escape sequence. Newlines become a literal `\n` within the output. Carriage
    77  returns become a literal `\r`.
    78  
    79  ## Message Types
    80  
    81  The set of machine-readable message types can be found in the
    82  [machine-readable format](/docs/machine-readable/index.html)
    83  complete documentation section. This section contains documentation
    84  on all the message types exposed by Packer core as well as all the
    85  components that ship with Packer by default.