DevOps https://kentrichards.net/ en Drupal, Composer, Patches, & FreeBSD, Oh My! https://kentrichards.net/blog/drupal-composer-patches-freebsd-oh-my <span>Drupal, Composer, Patches, &amp; FreeBSD, Oh My!</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>02/20/2020, 19:41</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h2>Problem</h2> <p>Composer is now the recommended way to install / manage Drupal. That's all fine and good. Composer generally works well. But...</p> <p>Incorporating patches into Drupal projects has become mainstream. So much so that <code>cweagans/composer-patches</code> is currently included in the standard Drupal composer template. Again, all fine and good. <code>cweagans/composer-patches</code> generally works well.</p> <p>Until it doesn't... Like <a href="https://github.com/cweagans/composer-patches/issues/182" rel="noreferrer">on FreeBSD and other OS's that don't support the <code>--no-backup-if-mismatch</code> option for the <code>patch</code> command</a>.</p> <p>Until that issue is resolved, FreeBSD users are out in the cold with <code>cweagans/composer-patches</code>. <code>composer install</code> fails if there are patches.</p> <h2>Solution</h2> <p>Here's what's working for me.</p> <h3>Remove <code>composer-exit-on-patch-failure</code> from <code>composer.json</code></h3> <p>We'll remove <code>cweagans/composer-patches</code> from the main project, but it may be installed anyway as a dependency of one the project's requirements. In that case, <code>cweagans/composer-patches</code> will still run and fail.</p> <p>To keep these failures from aborting the composer operation, make sure that this line isn't in the project's <code>composer.json</code>:</p> <pre> <code class="language-json">"composer-exit-on-patch-failure": true</code></pre><h3>Replace <code>cweagans/composer-patches</code></h3> <p>Replace <code>cweagans/composer-patches</code> in the project with <code>vaimo/composer-patches</code>.</p> <pre> <code class="language-bash">$ composer remove cweagans/composer-patches; composer require vaimo/composer-patches</code></pre><p>In my experience, these changes should fix the installation problems on FreeBSD.</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/drupal" hreflang="en">Drupal</a></div> <div class="field--item"><a href="/tag/devops" hreflang="en">DevOps</a></div> <div class="field--item"><a href="/tag/composer" hreflang="en">Composer</a></div> </div> </div> <section> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=86&amp;2=comment_no_subject&amp;3=comment_no_subject" token="IozMgIvBw4LiK45MJl1shKKxLsaYwVDCrOPHbH-uYh4"></drupal-render-placeholder> </section> Fri, 21 Feb 2020 03:41:09 +0000 kentr 86 at https://kentrichards.net Notes on Molecule https://kentrichards.net/blog/notes-molecule <span>Notes on Molecule</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>02/25/2019, 18:02</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>Notes to self...</p> <ul><li>Including Ansible variables from the python test file won't interpolate variables that are defined in the same file.   <p> For example, this won't work:</p> <pre> <code class="language-yaml">wp_deploy_dir: "/root/wordpress" wp_install_dir: "{{ wp_deploy_dir }}/wordpress/web"</code></pre><p> While this does work:</p> <pre> <code class="language-yaml">wp_deploy_dir: "/root/wordpress" wp_install_dir: "/root/wordpress/web"</code></pre></li> <li><code>ansible_env</code> doesn't change with <code>become</code>.  However, the resulting shell environment variables do change, such as <code>$HOME</code>.</li> <li>For faster development, it's possible to skip the <code>dependency</code> phase in <code>converge</code> by setting custom <code>converge_sequence</code> in <code>molecule.yml</code>.</li> <li>It's possible to debug the tests by: <ol><li>Run <code>molecule --debug verify</code> to get the exact <code>pytest</code> command that was run and the value for <code>MOLECULE_INVENTORY_FILE</code>.</li> <li>Go into the scenario directory.</li> <li>Run the pytest command that you got from step 1, but preface it with a statement that sets <code>MOLECULE_INVENTORY_FILE</code>.</li> </ol></li> <li>TravisCI has multiple time limits: <ul><li>Overall build time limit (50 minutes for public repos).</li> <li><a href="https://docs.travis-ci.com/user/common-build-problems/#build-times-out-because-no-output-was-received" rel="noreferrer">Timeout due to no output</a>.</li> </ul></li> <li>Molecule docker containers on MacOS are created with the default docker setup.  With Docker Desktop for Mac, this means that Docker—and therefore the molecule container—are running <em>inside</em> a <a href="https://github.com/moby/hyperkit" rel="noreferrer"><code>hyperkit</code></a> virtual machine. <ul><li>To "log in" to the VM running the container, use the <code>screen</code> command to attach to an existing terminal session inside the machine:<br /><pre> <code class="language-shell">$ screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty</code></pre><p> </p> </li> </ul></li> <li><code>host.run()</code> actually runs commands with the Ansible <code>command</code> module.  Variable interpolation does happen at this point, but the variables must be in the global Ansible runner namespace.</li> </ul></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/molecule" hreflang="en">Molecule</a></div> <div class="field--item"><a href="/tag/devops" hreflang="en">DevOps</a></div> <div class="field--item"><a href="/tag/testing" hreflang="en">Testing</a></div> </div> </div> <section> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=77&amp;2=comment_no_subject&amp;3=comment_no_subject" token="xP_Uvtpf0ojzeWHJ7AwFmjmlqKTsOf4iaVp4ZgA-ez0"></drupal-render-placeholder> </section> Tue, 26 Feb 2019 02:02:39 +0000 kentr 77 at https://kentrichards.net 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 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 Granting SUPER privilege on databases with DrupalVM https://kentrichards.net/blog/granting-super-privilege-databases-drupalvm <span>Granting SUPER privilege on databases with DrupalVM</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>03/03/2018, 09:37</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h2>Problem</h2> <p>I needed to grant the <code>SUPER</code> privilege to my Vagrant database user, and adding an item to <code>mysql_users</code> with <code>append_privs</code> per Ansible's <a href="http://docs.ansible.com/ansible/latest/mysql_user_module.html" rel="noreferrer"><code>mysql_user</code> module documentation</a> wasn't working for me.  </p> <h2>Solution</h2> <p>In your favorite local DrupalVM config file, redeclare the standard <code>mysql_users</code>, but add an additional privilege declaration in the <code>priv</code> property for <code>*.*:SUPER.</code></p> <pre> <code class="language-yaml">mysql_users: - name: "{{ drupal_db_user }}" host: "%" password: "{{ drupal_db_password }}" priv: "*.*:SUPER/{{ drupal_db_name }}.*:ALL" </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/drupalvm" hreflang="en">DrupalVM</a></div> <div class="field--item"><a href="/tag/ansible" hreflang="en">Ansible</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=66&amp;2=comment_no_subject&amp;3=comment_no_subject" token="Bt-EIg04YMxHhGBjpQVRmW3O46Qq5wp5tNoEvvpBdws"></drupal-render-placeholder> </section> Sat, 03 Mar 2018 17:37:05 +0000 kentr 66 at https://kentrichards.net Using a Python virtual environment on the remote machine with Ansible https://kentrichards.net/blog/using-python-virtual-environment-remote-machine-ansible <span>Using a Python virtual environment on the remote machine with Ansible</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>07/04/2017, 13:03</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h2>Problem</h2> <p>Recently I was working on a playbook to set up Apache basic HTTP authentication with the Ansible <code>htpasswd</code> module, and because the Python <code>passlib</code> module wasn't installed on the server I was getting an Ansible error:</p> <pre> <code class="language-json">"msg": "This module requires the passlib Python library"</code></pre><h2>Solution</h2> <p>I don't have <code>root</code> access to the server and could only install <code>passlib</code> in a Python virtual environment.  The problem then moved to Ansible—how to make Ansible use the virtual environment interpreter for the <code>htpasswd</code> task?</p> <p>The Ansible variable controlling the Python interpreter is <a href="http://docs.ansible.com/ansible/intro_inventory.html#list-of-behavioral-inventory-parameters" rel="noreferrer"><code>ansible_python_interpreter</code></a>.  I didn't find a way to directly set this variable for a specific task. What I did find is the <a href="http://docs.ansible.com/ansible/faq.html#how-can-i-set-the-path-or-any-other-environment-variable-for-a-task-or-entire-playbook" rel="noreferrer"><code>environment</code></a> parameter for tasks.  However, <a href="https://github.com/ansible/ansible/issues/6345#issuecomment-181981760" rel="noreferrer">there's no environment variable to directly specify <code>ansible_python_interpreter</code></a>.</p> <p>It is possible, though, to <a href="https://github.com/ansible/ansible/issues/6345#issuecomment-37129460" rel="noreferrer">tell Ansible to use the python that is specified by the environment</a>.</p> <p>With that glue in place, the next step is to specify the <code>$PATH</code> value for the specific task:</p> <pre> <code class="language-yaml">- name: Add users to .htpasswd file. htpasswd: path: path_to_htpasswd_file name: user_name password: password mode: 0644 # Use previously-installed python virtual env executable so that passlib is available. # This requires that ansible_python_interpreter = "/usr/bin/env python" environment: PATH: '{{ ansible_env.HOME }}/path_to_python_virtual_env/bin:{{ ansible_env.PATH }}'</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/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=61&amp;2=comment_no_subject&amp;3=comment_no_subject" token="bgUFX9f4MM6ZPbb7MJdJTgunG9aMMUpmSPdSBhUiOXY"></drupal-render-placeholder> </section> Tue, 04 Jul 2017 20:03:29 +0000 kentr 61 at https://kentrichards.net 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 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 Gulpfile for browser-sync reload server with Drupal development https://kentrichards.net/blog/gulpfile-browser-sync-reload-server-drupal-development <span>Gulpfile for browser-sync reload server with Drupal development</span> <span><span lang="" about="/users/kentr" typeof="schema:Person" property="schema:name" datatype="">kentr</span></span> <span>07/23/2016, 17:30</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>Here's a gulpfile for using browser-sync-based reload with Sass: </p> <p><a href="https://github.com/kentr/drupal-gulp-browser-sync" rel="noreferrer">https://github.com/kentr/drupal-gulp-browser-sync</a></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/drupal8" hreflang="en">Drupal8</a></div> <div class="field--item"><a href="/tag/devops" hreflang="en">DevOps</a></div> <div class="field--item"><a href="/tag/sass" hreflang="en">Sass</a></div> </div> </div> <section> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=54&amp;2=comment_no_subject&amp;3=comment_no_subject" token="iL0FaK0bBsj_p0NPq-4WcWW6nSeu_sLIm5ClJUFMb0c"></drupal-render-placeholder> </section> Sun, 24 Jul 2016 00:30:12 +0000 kentr 54 at https://kentrichards.net