<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Homebrew &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/homebrew/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Wed, 04 Sep 2024 15:45:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Homebrew &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Ansible: Handling Sudo Password with Homebrew</title>
		<link>https://myshittycode.com/2024/09/04/ansible-handling-sudo-password-with-homebrew/</link>
					<comments>https://myshittycode.com/2024/09/04/ansible-handling-sudo-password-with-homebrew/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Wed, 04 Sep 2024 15:45:24 +0000</pubDate>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Ansible]]></category>
		<category><![CDATA[Homebrew]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=2665</guid>

					<description><![CDATA[<p>Problem When using the Ansible playbook to run Homebrew-related modules, it will prompt for a sudo password where necessary on specific tasks. For example, using the community.general.homebrew_cask module to (un)install the apps under /Applications directory will prompt for a sudo password on each app. It is not possible to preemptively prompt for a sudo password [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2024/09/04/ansible-handling-sudo-password-with-homebrew/">Ansible: Handling Sudo Password with Homebrew</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-rank-math-toc-block" id="rank-math-toc"><h2>Table of Contents</h2><nav><ul><li><a href="#problem">Problem</a></li><li><a href="#does-not-work-too">Root Cause</a></li><li><a href="#solution">Solution</a></li></ul></nav></div>



<h2 class="wp-block-heading" id="problem">Problem</h2>



<p>When using the Ansible playbook to run Homebrew-related modules, it will prompt for a sudo password where necessary on specific tasks. For example, using the <a href="https://docs.ansible.com/ansible/latest/collections/community/general/homebrew_cask_module.html" target="_blank" rel="noopener">community.general.homebrew_cask</a> module to (un)install the apps under /Applications directory will prompt for a sudo password on each app.</p>



<p>It is not possible to preemptively prompt for a sudo password before running the Ansible playbook:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; highlight: [2]; title: ; notranslate">
# Does not work!
sudo -v

ansible-playbook main.yml
</pre></div>


<p>It is also not possible to perform <a href="https://gist.github.com/cowboy/3118588" target="_blank" rel="noopener">clever tricks like this</a> to extend the sudo timeout:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; highlight: [2]; title: ; notranslate">
# Does not work, too!
while true; do sudo -n true; sleep 60; kill -0 &quot;$$&quot; || exit; done 2&gt;/dev/null &amp;

ansible-playbook main.yml
</pre></div>


<h2 class="wp-block-heading" id="does-not-work-too">Root Cause</h2>



<p>This is not an Ansible problem. This behavior exists because Homebrew always clears the sudo password cache to prevent privilege escalation attacks [<a href="https://github.com/Homebrew/brew/issues/17905" target="_blank" rel="noopener">link 1</a>] [<a href="https://github.com/Homebrew/brew/pull/17694/commits/2adf25dcaf8d8c66124c5b76b8a41ae228a7bb02" target="_blank" rel="noopener">link 2</a>].</p>



<p>The upside is the <strong>community.general.homebrew_cask</strong> module provides a variable for passing in a sudo password, for example:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; highlight: [7]; title: ; notranslate">
- name: Install/Upgrade cask packages
  community.general.homebrew_cask:
    name: &#039;{{ item }}&#039;
    state: upgraded
    greedy: true
    install_options: force,no-quarantine
    sudo_password: &quot;{{ ansible_become_pass }}&quot;
  loop: &#039;{{ homebrew_cask_packages_present }}&#039;
</pre></div>


<h2 class="wp-block-heading" id="solution">Solution</h2>



<p>While storing passwords in a file is not ideal, it prevents these Ansible tasks from prompting for a sudo password each time. The <strong>ansible-vault</strong> command can be used to store the password (and other secrets) securely.</p>



<p>First, create an encrypted file.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
ansible-vault create vault.yml
</pre></div>


<p>You will be prompted for a new vault password. Once provided, enter the following into the file.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
ansible_become_pass: &#x5B;YOUR_SUDO_PASSWORD]
</pre></div>


<p>Now, your encrypted file should be created in the location you specified with the proper permission set:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; highlight: [18]; title: ; notranslate">
$ ls -la
total 88
drwxr-xr-x@ 18 shitty.author  staff   576 Sep  4 09:06 .
drwxr-xr-x  12 shitty.author  staff   384 Jun 27 12:47 ..
-rw-r--r--   1 shitty.author  staff    99 Mar  1  2024 .ansible-lint
-rw-r--r--   1 shitty.author  staff   193 Mar 19 08:57 .editorconfig
drwxr-xr-x  16 shitty.author  staff   512 Sep  4 09:06 .git
-rw-r--r--   1 shitty.author  staff   243 Mar  1  2024 .gitignore
drwxr-xr-x   8 shitty.author  staff   256 Sep  4 09:35 .idea
drwxr-xr-x   6 shitty.author  staff   192 Mar  4  2024 .venv
-rw-r--r--   1 shitty.author  staff    72 Mar  1  2024 .yamllint
-rw-r--r--   1 shitty.author  staff  1079 Mar  1  2024 LICENSE.md
-rw-r--r--@  1 shitty.author  staff  1796 Sep  4 08:39 README.md
-rw-r--r--   1 shitty.author  staff   381 Mar  1  2024 ansible.cfg
-rw-r--r--   1 shitty.author  staff    65 Mar  1  2024 inventory.yml
-rw-r--r--@  1 shitty.author  staff  1450 Sep  4 09:06 main.yml
drwxr-xr-x  16 shitty.author  staff   512 Aug 12 09:32 roles
-rw-------@  1 shitty.author  staff   484 Sep  4 09:01 vault.yml
</pre></div>


<p>If you open vault.yml, the content should look gibberish.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
$ cat vault.yml                                                                                  ✔
$ANSIBLE_VAULT;1.1;AES256
62343635616463643935613965336336323366653565646137616238663266633936363463611364
6139353639666163323066653733663763323236663361380a646264623465616461646637315661
34396438316137383130366330313431653336396435656562356430333762373866663234383230
6265656164346531660a626431383230326664393839316131626330353562363164313439661863
31343363323236333531303139396662386531626165663732386233626538646338333133375936
6535626465393233386634393934623438393535626365313132
</pre></div>


<p>In the Ansible playbook, specify vault.yml under <strong>vars_files</strong>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; highlight: [4,5]; title: ; notranslate">
---
- name: My Playbook
  hosts: all
  vars_files:
    - vault.yml
  roles:
    - ...
</pre></div>


<p>Finally, run the Ansible playbook with the <strong>&#8211;ask-vault-pass</strong> option, where you will be prompted for the vault password once before Ansible executes the playbook.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
ansible-playbook main.yml --ask-vault-pass
</pre></div>


<p>Now, you will not be prompted for a sudo password every time Homebrew-related tasks run.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2024/09/04/ansible-handling-sudo-password-with-homebrew/">Ansible: Handling Sudo Password with Homebrew</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2024/09/04/ansible-handling-sudo-password-with-homebrew/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2665</post-id>	</item>
		<item>
		<title>Homebrew: &#8220;Invalid Multibyte Escape&#8221; Error</title>
		<link>https://myshittycode.com/2013/11/09/homebrew-invalid-multibyte-escape-error/</link>
					<comments>https://myshittycode.com/2013/11/09/homebrew-invalid-multibyte-escape-error/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Sat, 09 Nov 2013 15:43:38 +0000</pubDate>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Homebrew]]></category>
		<category><![CDATA[MacOS]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=219</guid>

					<description><![CDATA[<p>PROBLEM When running brew on OS X Maverick, you get this error:- SOLUTION After upgrading to OS X Mavericks, the default version of Ruby is v2.0, causing Homebrew to break because it relies on v1.8. See issue #23655 for more information. To fix this, run the following command:- If you are getting the &#8220;Permission Denied&#8221; [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2013/11/09/homebrew-invalid-multibyte-escape-error/">Homebrew: &#8220;Invalid Multibyte Escape&#8221; Error</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>When running <b>brew</b> on OS X Maverick, you get this error:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Error: /usr/local/Library/Homebrew/download_strategy.rb:84: invalid multibyte escape: /^\037\213/
invalid multibyte escape: /^\037\235/
Please report this bug: https://github.com/mxcl/homebrew/wiki/Checklist-before-filing-a-new-issue
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require&#039;
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require&#039;
</pre></div>


<h2 class="wp-block-heading">SOLUTION</h2>



<p>After upgrading to OS X Mavericks, the default version of Ruby is v2.0, causing Homebrew to break because it relies on v1.8. See <a href="https://github.com/mxcl/homebrew/issues/23655" target="_blank" rel="noopener">issue #23655</a> for more information.</p>



<p>To fix this, run the following command:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
brew update
</pre></div>


<p>If you are getting the &#8220;Permission Denied&#8221; errors when running the above command, run the following command to fix the permission problem:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
# Assuming your user name is USER_HERO
sudo chown -R USER_HERO:admin /usr/local
cd /usr/local
git reset --hard origin/master
brew update
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2013/11/09/homebrew-invalid-multibyte-escape-error/">Homebrew: &#8220;Invalid Multibyte Escape&#8221; Error</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2013/11/09/homebrew-invalid-multibyte-escape-error/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">219</post-id>	</item>
		<item>
		<title>&#8220;tree&#8221; Command on Mac OS X</title>
		<link>https://myshittycode.com/2013/10/07/tree-command-on-mac-os-x/</link>
					<comments>https://myshittycode.com/2013/10/07/tree-command-on-mac-os-x/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Mon, 07 Oct 2013 16:04:00 +0000</pubDate>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Homebrew]]></category>
		<category><![CDATA[MacOS]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=138</guid>

					<description><![CDATA[<p>So, I have been drawing the ASCII file structure tree by hand lately&#8230; and that is dumb and time consuming. After digging around, I found a great way to do so. First, if you don&#8217;t have Homebrew, install it first. Run the following command to install the tree command:- Now, you can run the following [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/07/tree-command-on-mac-os-x/">&#8220;tree&#8221; Command on Mac OS X</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>So, I have been drawing the ASCII file structure tree by hand lately&#8230; and that is dumb and time consuming. After digging around, I found a great way to do so.</p>



<p>First, if you don&#8217;t have <a href="http://brew.sh/" target="_blank" rel="noopener">Homebrew</a>, install it first.</p>



<p>Run the following command to install the <b>tree</b> command:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
brew install tree
</pre></div>


<p>Now, you can run the following command to create a tree:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
tree &#x5B;directory]
</pre></div>


<p>For example:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
tree testMe
</pre></div>


<p>&#8230; generates:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
testMe
├── src
├── testMe.iml
└── web
    ├── WEB-INF
    │   ├── lib
    │   └── web.xml
    └── index.jsp
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/07/tree-command-on-mac-os-x/">&#8220;tree&#8221; Command on Mac OS X</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2013/10/07/tree-command-on-mac-os-x/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">138</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-20 06:14:08 by W3 Total Cache
-->