github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/website/source/docs/other/debugging.html.md (about)

     1  ---
     2  description: |
     3      Packer strives to be stable and bug-free, but issues inevitably arise where
     4      certain things may not work entirely correctly, or may not appear to work
     5      correctly.
     6  layout: docs
     7  page_title: 'Debugging - Other'
     8  sidebar_current: 'docs-other-debugging'
     9  ---
    10  
    11  # Debugging Packer Builds
    12  
    13  Using `packer build -on-error=ask` allows you to inspect failures and try out
    14  solutions before restarting the build.
    15  
    16  For remote builds with cloud providers like Amazon Web Services AMIs, debugging
    17  a Packer build can be eased greatly with `packer build -debug`. This disables
    18  parallelization and enables debug mode.
    19  
    20  Debug mode informs the builders that they should output debugging information.
    21  The exact behavior of debug mode is left to the builder. In general, builders
    22  usually will stop between each step, waiting for keyboard input before
    23  continuing. This will allow you to inspect state and so on.
    24  
    25  In debug mode once the remote instance is instantiated, Packer will emit to the
    26  current directory an ephemeral private ssh key as a .pem file. Using that you
    27  can `ssh -i <key.pem>` into the remote build instance and see what is going on
    28  for debugging. The key will only be emitted for cloud-based builders. The
    29  ephemeral key will be deleted at the end of the packer run during cleanup.
    30  
    31  For a local builder, the SSH session initiated will be visible in the detail
    32  provided when `PACKER_LOG=1` environment variable is set prior to a build,
    33  and you can connect to the local machine using the userid and password defined
    34  in the kickstart or preseed associated with initializing the local VM.
    35  
    36  ### Windows
    37  
    38  As of Packer 0.8.1 the default WinRM communicator will emit the password for a
    39  Remote Desktop Connection into your instance. This happens following the several
    40  minute pause as the instance is booted. Note a .pem key is still created for
    41  securely transmitting the password. Packer automatically decrypts the password
    42  for you in debug mode.
    43  
    44  ## Debugging Packer
    45  
    46  Issues occasionally arise where certain things may not work entirely correctly,
    47  or may not appear to work correctly. In these cases, it is sometimes helpful to
    48  see more details about what Packer is actually doing.
    49  
    50  Packer has detailed logs which can be enabled by setting the `PACKER_LOG`
    51  environmental variable to any value but `""` (empty string) and `"0"` like this
    52  `PACKER_LOG=1 packer build <config.json>`. This will cause detailed logs to
    53  appear on stderr. The logs contain log messages from Packer as well as any
    54  plugins that are being used. Log messages from plugins are prefixed by their
    55  application name.
    56  
    57  Note that because Packer is highly parallelized, log messages sometimes appear
    58  out of order, especially with respect to plugins. In this case, it is important
    59  to pay attention to the timestamp of the log messages to determine order.
    60  
    61  In addition to simply enabling the log, you can set `PACKER_LOG_PATH` in order
    62  to force the log to always go to a specific file when logging is enabled. Note
    63  that even when `PACKER_LOG_PATH` is set, `PACKER_LOG` must be set in order for
    64  any logging to be enabled.
    65  
    66  ### Debugging Packer in Powershell/Windows
    67  
    68  In Windows you can set the detailed logs environmental variable `PACKER_LOG` or
    69  the log variable `PACKER_LOG_PATH` using powershell environment variables. For
    70  example:
    71  
    72  ``` powershell
    73  $env:PACKER_LOG=1
    74  $env:PACKER_LOG_PATH="packerlog.txt"
    75  ```
    76  
    77  If you find a bug with Packer, please include the detailed log by using a
    78  service such as [gist](https://gist.github.com).
    79  
    80  ## Issues Installing Ubuntu Packages
    81  
    82  Issues may arise using and building Ubuntu AMIs where common packages that
    83  *should* be installed from Ubuntu's Main repository are not found during a
    84  provisioner step:
    85  
    86      amazon-ebs: No candidate version found for build-essential
    87      amazon-ebs: No candidate version found for build-essential
    88  
    89  This, obviously can cause problems where a build is unable to finish
    90  successfully as the proper packages cannot be provisioned correctly. The problem
    91  arises when cloud-init has not finished fully running on the source AMI by the
    92  time that packer starts any provisioning steps.
    93  
    94  Adding the following provisioner to the packer template, allows for the
    95  cloud-init process to fully finish before packer starts provisioning the source
    96  AMI.
    97  
    98  ``` json
    99  {
   100    "type": "shell",
   101    "inline": [
   102      "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done"
   103    ]
   104  }
   105  ```
   106  
   107  ## Issues when using numerous Builders/Provisioners/Post-Processors
   108  
   109  Packer uses a separate process for each builder, provisioner, post-processor,
   110  and plugin. In certain cases, if you have too many of these, you can run out of
   111  [file descriptors](https://en.wikipedia.org/wiki/File_descriptor). This results
   112  in an error that might look like
   113  
   114  ``` text
   115  error initializing provisioner 'powershell': fork/exec /files/go/bin/packer:
   116  too many open files
   117  ```
   118  
   119  On Unix systems, you can check what your file descriptor limit is with `ulimit -Sn`. You should check with your OS vendor on how to raise this limit.
   120  
   121  ## Issues when using long temp directory
   122  
   123  Packer uses unix sockets internally, which are created inside the default
   124  directory for temporary files. Some operating systems place a limit on the
   125  length of the socket name, usually between 80 and 110 characters. If you get an
   126  error like this (for any builder, not just docker):
   127  
   128  ``` text
   129  Failed to initialize build 'docker': error initializing builder 'docker': plugin exited before we could connect
   130  ```
   131  
   132  you should try setting your temp directory to something shorter. This can be
   133  done through the `TMPDIR` environment variable.