github.com/ratanraj/packer@v1.3.2/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  It should be noted that one of the options `-on-error` is to `retry`, the retry
    37  of the step in question has limitations:
    38  
    39   * the template packer is building is **not** reloaded from file.
    40   * the resources specified from builders **are** reloaded from file.
    41  
    42  Check the specfics on your builder to confirm their behavior.
    43  
    44  ### Windows
    45  
    46  As of Packer 0.8.1 the default WinRM communicator will emit the password for a
    47  Remote Desktop Connection into your instance. This happens following the several
    48  minute pause as the instance is booted. Note a .pem key is still created for
    49  securely transmitting the password. Packer automatically decrypts the password
    50  for you in debug mode.
    51  
    52  ## Debugging Packer
    53  
    54  Issues occasionally arise where certain things may not work entirely correctly,
    55  or may not appear to work correctly. In these cases, it is sometimes helpful to
    56  see more details about what Packer is actually doing.
    57  
    58  Packer has detailed logs which can be enabled by setting the `PACKER_LOG`
    59  environmental variable to any value but `""` (empty string) and `"0"` like this
    60  `PACKER_LOG=1 packer build <config.json>`. This will cause detailed logs to
    61  appear on stderr. The logs contain log messages from Packer as well as any
    62  plugins that are being used. Log messages from plugins are prefixed by their
    63  application name.
    64  
    65  Note that because Packer is highly parallelized, log messages sometimes appear
    66  out of order, especially with respect to plugins. In this case, it is important
    67  to pay attention to the timestamp of the log messages to determine order.
    68  
    69  In addition to simply enabling the log, you can set `PACKER_LOG_PATH` in order
    70  to force the log to always go to a specific file when logging is enabled. Note
    71  that even when `PACKER_LOG_PATH` is set, `PACKER_LOG` must be set in order for
    72  any logging to be enabled.
    73  
    74  ### Debugging Packer in Powershell/Windows
    75  
    76  In Windows you can set the detailed logs environmental variable `PACKER_LOG` or
    77  the log variable `PACKER_LOG_PATH` using powershell environment variables. For
    78  example:
    79  
    80  ``` powershell
    81  $env:PACKER_LOG=1
    82  $env:PACKER_LOG_PATH="packerlog.txt"
    83  ```
    84  
    85  If you find a bug with Packer, please include the detailed log by using a
    86  service such as [gist](https://gist.github.com).
    87  
    88  ## Issues Installing Ubuntu Packages
    89  
    90  Issues may arise using and building Ubuntu AMIs where common packages that
    91  *should* be installed from Ubuntu's Main repository are not found during a
    92  provisioner step:
    93  
    94      amazon-ebs: No candidate version found for build-essential
    95      amazon-ebs: No candidate version found for build-essential
    96  
    97  This, obviously can cause problems where a build is unable to finish
    98  successfully as the proper packages cannot be provisioned correctly. The problem
    99  arises when cloud-init has not finished fully running on the source AMI by the
   100  time that packer starts any provisioning steps.
   101  
   102  Adding the following provisioner to the packer template, allows for the
   103  cloud-init process to fully finish before packer starts provisioning the source
   104  AMI.
   105  
   106  ``` json
   107  {
   108    "type": "shell",
   109    "inline": [
   110      "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done"
   111    ]
   112  }
   113  ```
   114  
   115  ## Issues when using numerous Builders/Provisioners/Post-Processors
   116  
   117  Packer uses a separate process for each builder, provisioner, post-processor,
   118  and plugin. In certain cases, if you have too many of these, you can run out of
   119  [file descriptors](https://en.wikipedia.org/wiki/File_descriptor). This results
   120  in an error that might look like
   121  
   122  ``` text
   123  error initializing provisioner 'powershell': fork/exec /files/go/bin/packer:
   124  too many open files
   125  ```
   126  
   127  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.
   128  
   129  ## Issues when using long temp directory
   130  
   131  Packer uses unix sockets internally, which are created inside the default
   132  directory for temporary files. Some operating systems place a limit on the
   133  length of the socket name, usually between 80 and 110 characters. If you get an
   134  error like this (for any builder, not just docker):
   135  
   136  ``` text
   137  Failed to initialize build 'docker': error initializing builder 'docker': plugin exited before we could connect
   138  ```
   139  
   140  you should try setting your temp directory to something shorter. This can be
   141  done through the `TMPDIR` environment variable.