Vagrant https://kentrichards.net/ en Vagrant / Ansible, Could not get lock /var/lib/dpkg/lock https://kentrichards.net/blog/vagrant-ansible-could-not-get-lock-varlibdpkglock <span>Vagrant / Ansible, Could not get lock /var/lib/dpkg/lock</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>01/11/2019, 19:55</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h2>Problem</h2> <p>To save time when provisioning and reduce the size of VMs using linked clones, I packaged a pre-provisioned Vagrant box as a base to use with standard LAMP apps.</p> <p>Ansible still provisions on <code>vagrant up</code> to customize the box for the project, and it periodically fails with the error</p> <pre> <code class="language-no-highlight language-shell">Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?</code></pre><h2>Solution</h2> <p>A bit of searching led me to <a href="https://github.com/hashicorp/vagrant/issues/7508#issuecomment-281332526" rel="noreferrer">this similar issue</a>.</p> <p>Instead of changing the provisioning, I made the suggested periodic configuration change in the base box:</p> <pre> <code class="language-shell">$ sudo sh -c "echo 'APT::Periodic::Enable \"0\";' &gt; /etc/apt/apt.conf.d/02periodic"</code></pre><p>Then, I repackaged the box to use it as a base, with the configuration already set.</p> <p>So far this appears to have solved the problem.</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/vagrant" hreflang="en">Vagrant</a></div> <div class="field--item"><a href="/tag/devops" hreflang="en">DevOps</a></div> </div> </div> <section> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=71&amp;2=comment_no_subject&amp;3=comment_no_subject" token="ozSVAFSrATu_dPbeVgzTdhwl3itBnKlZwWkooSmURtA"></drupal-render-placeholder> </section> Sat, 12 Jan 2019 03:55:47 +0000 kentr 71 at https://kentrichards.net https://kentrichards.net/blog/vagrant-ansible-could-not-get-lock-varlibdpkglock#comments Transferring a Vagrant box to a new host machine (VirtualBox) https://kentrichards.net/blog/transferring-vagrant-box-new-host-machine-virtualbox <span>Transferring a Vagrant box to a new host machine (VirtualBox)</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>05/10/2018, 15:31</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h2>Problem</h2> <p>I recently switched to a new machine, and for various reasons some of my Vagrant boxes didn't transfer in the migration.  <code>vagrant status</code> resulted in a status of "not created (virtualbox)".</p> <p>Since Vagrant boxes are supposed to be disposable and reproducible, in most cases this was fine.</p> <p>But there were a couple that I wanted to transfer as-is.  This is how I did it.</p> <h2>Solution</h2> <ol><li>On the first machine, halt the Vagrant box.</li> <li>Copy the actual VirtualBox machine files.  On the Mac, these are in <code>~/VirtualBox VMs</code>.</li> <li>Open the VirtualBox GUI, and choose <strong>Machine &gt; Add</strong>.</li> <li>Navigate to the machine and add it, so that it appears in the VirtualBox GUI.</li> <li>Under the Vagrant project directory, copy the files for the Vagrant box in question under <code>.vagrant/machines</code> into the <code>.vagrant/machines</code> directory under the corresponding Vagrant directory on the new machine.</li> <li>In the Vagrant directory, double-check the machine's status with <code>vagrant status</code>.  It should be "poweroff" instead of "not created".</li> <li>At this point, you should be able to run <code>vagrant up</code> or <code>vagrant reload</code> as normal.</li> </ol></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/vagrant" hreflang="en">Vagrant</a></div> <div class="field--item"><a href="/tag/devops" hreflang="en">DevOps</a></div> </div> </div> <section> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=67&amp;2=comment_no_subject&amp;3=comment_no_subject" token="39-pjck5mEfPcMrh65Ja_sRBfUSunbEod_pZ0FzNIyI"></drupal-render-placeholder> </section> Thu, 10 May 2018 22:31:23 +0000 kentr 67 at https://kentrichards.net https://kentrichards.net/blog/transferring-vagrant-box-new-host-machine-virtualbox#comments Bypass known_hosts file for Vagrant boxes https://kentrichards.net/blog/bypass-knownhosts-file-vagrant-boxes <span>Bypass known_hosts file for Vagrant boxes</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>03/19/2017, 12:26</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h2>Problem</h2> <p>As Vagrant boxes are created &amp; destroyed, the entries in <code>~/.ssh/known_hosts</code> become obsolete, and SSH throws warnings or fails with <code>vagrant ssh</code>, <code>drush</code> operations, etc.</p> <h2>Solution</h2> <p>Add these lines to <code>~/.ssh/config</code></p> <pre> <code class="language-ini">###################################################### # Vagrant ###################################################### Host 192.168.*.* StrictHostKeyChecking no UserKnownHostsFile /dev/null Host local.*.* StrictHostKeyChecking no UserKnownHostsFile /dev/null Host *.loc StrictHostKeyChecking no UserKnownHostsFile /dev/null</code></pre><p> </p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/vagrant" hreflang="en">Vagrant</a></div> <div class="field--item"><a href="/tag/devops" hreflang="en">DevOps</a></div> </div> </div> <section> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=60&amp;2=comment_no_subject&amp;3=comment_no_subject" token="Nh2FLaA0r7_sy37wEWx3O8NTQfk5qCT81NDYSaX_b1U"></drupal-render-placeholder> </section> Sun, 19 Mar 2017 19:26:19 +0000 kentr 60 at https://kentrichards.net https://kentrichards.net/blog/bypass-knownhosts-file-vagrant-boxes#comments Operation not permitted error, Vagrant-cachier, Ansible Unarchive module https://kentrichards.net/blog/operation-not-permitted-error-vagrant-cachier-ansible-unarchive-module <span>Operation not permitted error, Vagrant-cachier, Ansible Unarchive module</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>12/29/2016, 09:37</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h2>Problem:</h2> <p>Setting up DrupalVM to use the <code>vagrant-cachier</code> plugin, I was getting "Operation not permitted ..." errors in the task <code>Untar Xdebug</code>.</p> <p>Apparently, because the task was running with <code>become</code>,  <code>tar</code> was trying to change the owner / group of the unarchived files.  From the man page:</p> <pre> <code class="language-plaintext">--same-owner try extracting files with the same ownership as exists in the archive (default for superuser)</code></pre><p>However, on an <code>nfs</code> synced folder, that's not allowed.</p> <h2>Solution:</h2> <p>Add <code>--no-same-owner</code> as an <code>extra_opts</code> argument:</p> <pre> <code class="language-yaml">- name: Untar some file. unarchive: src: "https://example.com/archive.tgz" dest: "/some/dir" extra_opts: "--no-same-owner" creates: "/some/dir/unarchived" copy: No</code></pre><p> </p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/ansible" hreflang="en">Ansible</a></div> <div class="field--item"><a href="/tag/vagrant" hreflang="en">Vagrant</a></div> <div class="field--item"><a href="/tag/devops" hreflang="en">DevOps</a></div> </div> </div> <section> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=58&amp;2=comment_no_subject&amp;3=comment_no_subject" token="3Wfdz4mvUhn-ltoWGwIcTbAImChrPyQrSKhkeAjIK2M"></drupal-render-placeholder> </section> Thu, 29 Dec 2016 17:37:49 +0000 kentr 58 at https://kentrichards.net SequelPro SSH connection to vagrant https://kentrichards.net/blog/sequelpro-ssh-connection-vagrant <span>SequelPro SSH connection to vagrant</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>03/06/2015, 21:34</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h2>Problem:</h2> <p>Configure SequelPro connection over SSH to MySQL running on a Vagrant box.</p> <h2>Solution:</h2> <ol><li>Set up vagrant VM with MySQL database and user as usual.</li> <li>Add Host entry for VM to .ssh/config.  Not strictly necessary, but also allows standard SSH connections, piping, etc:<br />   <pre> <code class="language-ini"># 'vagrant' as alias for the host Host vagrant # Values from vagrant ssh-config HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile $HOME/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL</code></pre></li> <li>SequelPro setup <ul><li>Use SSH connection type</li> <li><strong>MySQL Host:</strong> 127.0.0.1</li> <li><strong>Username:</strong> &lt;MySQL user on VM&gt;</li> <li><strong>Password:</strong> &lt;MySQL password on VM&gt;</li> <li><strong>Database:</strong> &lt;MySQL database VM&gt;</li> <li><strong>Port:</strong> &lt;MySQL port on VM&gt;</li> <li><strong>SSH Host:</strong> vagrant</li> <li><strong>SSH User:</strong> vagrant</li> </ul></li> </ol></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/vagrant" hreflang="en">Vagrant</a></div> </div> </div> <section> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=47&amp;2=comment_no_subject&amp;3=comment_no_subject" token="uUDZzT8Dkb1mT7AM2cJp5n3A2LoqdJQ-JEkOJc0Angg"></drupal-render-placeholder> </section> Sat, 07 Mar 2015 05:34:36 +0000 kentr 47 at https://kentrichards.net https://kentrichards.net/blog/sequelpro-ssh-connection-vagrant#comments