<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>linux on Andrew Beaton</title>
    <link>https://andrewbeaton.net/tags/linux/</link>
    <description>Recent content in linux on Andrew Beaton</description>
    <image>
      <title>Andrew Beaton</title>
      <url>https://andrewbeaton.net/me.jpeg</url>
      <link>https://andrewbeaton.net/me.jpeg</link>
    </image>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Tue, 18 Feb 2020 00:00:00 +0000</lastBuildDate><atom:link href="https://andrewbeaton.net/tags/linux/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Using Terraform to create an LXC on Proxmox</title>
      <link>https://andrewbeaton.net/posts/2020/02/using-terraform-to-create-lxc-on-proxmox/</link>
      <pubDate>Tue, 18 Feb 2020 00:00:00 +0000</pubDate>
      
      <guid>https://andrewbeaton.net/posts/2020/02/using-terraform-to-create-lxc-on-proxmox/</guid>
      <description>Using Terraform to create an LXC on Proxmox</description>
      <content:encoded><![CDATA[<p>I’ve been looking at automating as much of my home lab that’s running on <a href="https://www.proxmox.com/en/">Proxmox</a>  as possible, not only to get things up and running quickly should a failure happen but also to keep my skills current with the various automation tools out there at the moment.</p>
<p>From my previous posts, you can see that I use <a href="https://www.ansible.com/">Ansible</a> a fair bit for my personal projects, but at work, being a C# developer and working for an organisation that is predominantly Microsoft based, we use <a href="https://www.terraform.io/">Terraform</a> by HashiCorp for infrastructure automation.</p>
<p>I’ve been keeping a close eye on a project by Telmate on Github. They have been working on the <a href="https://github.com/Telmate/terraform-provider-proxmox">Terraform Proxmox Provider</a> and a few days ago a commit was made to allow the creation of <a href="https://en.wikipedia.org/wiki/LXC">Linux Containers (LXC)</a> in Proxmox as opposed to just the creation of Virtual Machines (VMs), so I was keen to give it a go.</p>
<h2 id="requirements">Requirements</h2>
<p>I’m using macOS Catalina as my development machine, so the instructions will be based on this platform, but the tools will be the same and installation may differ.</p>
<h4 id="go">Go</h4>
<p>Download and install Go from <a href="https://golang.org/dl/">Go’s website</a>. Or by a direct link to <a href="https://golang.org/doc/install?download=go1.13.3.darwin-amd64.pkg">MacOS Go 1.13.3</a></p>
<h4 id="terraform-provider-and-provisioner">Terraform Provider and Provisioner</h4>
<p>Using Go, get the latest Terraform provider and provisioner for Proxmox.</p>
<p>These instructions differ slightly from those on the <a href="https://github.com/Telmate/terraform-provider-proxmox">Terraform Proxmox Provider</a> Github page, but they are what worked for me.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-Go" data-lang="Go"><span style="display:flex;"><span><span style="color:#66d9ef">go</span> <span style="color:#a6e22e">get</span> <span style="color:#a6e22e">github</span>.<span style="color:#a6e22e">com</span><span style="color:#f92672">/</span><span style="color:#a6e22e">Telmate</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span><span style="color:#f92672">/</span><span style="color:#a6e22e">cmd</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">go</span> <span style="color:#a6e22e">install</span> <span style="color:#a6e22e">github</span>.<span style="color:#a6e22e">com</span><span style="color:#f92672">/</span><span style="color:#a6e22e">Telmate</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span><span style="color:#f92672">/</span><span style="color:#a6e22e">cmd</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">go</span> <span style="color:#a6e22e">get</span> <span style="color:#a6e22e">github</span>.<span style="color:#a6e22e">com</span><span style="color:#f92672">/</span><span style="color:#a6e22e">Telmate</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span><span style="color:#f92672">/</span><span style="color:#a6e22e">cmd</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provisioner</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">go</span> <span style="color:#a6e22e">install</span> <span style="color:#a6e22e">github</span>.<span style="color:#a6e22e">com</span><span style="color:#f92672">/</span><span style="color:#a6e22e">Telmate</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span><span style="color:#f92672">/</span><span style="color:#a6e22e">cmd</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provisioner</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span>
</span></span></code></pre></div><p>Copy them to the correct locations:</p>
<pre tabindex="0"><code>which terraform-provider-proxmox
~/go-workspace/bin/terraform-provider-proxmox
which terraform-provisioner-proxmox
~/go-workspace/bin/terraform-provisioner-proxmox 

cd ~/.terraform.d
mkdir plugins
cd plugins
cp ~/go-workspace/bin/terraform-provider-proxmox .
cp ~/go-workspace/bin/terraform-provisioner-proxmox .
</code></pre><h4 id="example-of-container-creation">Example of container creation</h4>
<p>Using the example below, after updating your own values, a new container will be created, ready to be started.</p>
<p>I found it simple enough to create a new container using the Proxmox GUI and comparing the values with the resources in the example below and a little trial and error.</p>
<p>For a list of all the resources available that you can set, it’s worth having a read through of the <a href="https://github.com/Telmate/terraform-provider-proxmox/blob/master/proxmox/resource_lxc.go">resource_lxc.go</a> code on Github.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>provider <span style="color:#e6db74">&#34;proxmox&#34;</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    pm_tls_insecure <span style="color:#f92672">=</span> true
</span></span><span style="display:flex;"><span>    pm_api_url <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;https://proxmox.home.lan:8006/api2/json&#34;</span>
</span></span><span style="display:flex;"><span>    pm_user <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;terraform@pam&#34;</span>
</span></span><span style="display:flex;"><span>    pm_password <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&lt;secure password&gt;&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>resource <span style="color:#e6db74">&#34;proxmox_lxc&#34;</span> <span style="color:#e6db74">&#34;lxc-test&#34;</span> <span style="color:#f92672">{</span> 
</span></span><span style="display:flex;"><span>    hostname <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;lxc-test-host&#34;</span>
</span></span><span style="display:flex;"><span>    cores <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>    memory <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;1024&#34;</span>
</span></span><span style="display:flex;"><span>    swap <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;2048&#34;</span>
</span></span><span style="display:flex;"><span>    network <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>        name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;eth0&#34;</span>
</span></span><span style="display:flex;"><span>        bridge <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;vmbr0&#34;</span>
</span></span><span style="display:flex;"><span>        ip <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;192.168.1.69/24&#34;</span>  
</span></span><span style="display:flex;"><span>        firewall <span style="color:#f92672">=</span> true
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>    ostemplate <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;local:vztmpl/ubuntu-18.04-custom.tar.gz&#34;</span> 
</span></span><span style="display:flex;"><span>    password <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&lt;secure password&gt;&#34;</span>
</span></span><span style="display:flex;"><span>    pool <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;terraform&#34;</span>
</span></span><span style="display:flex;"><span>    rootfs <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;local-lvm2:8&#34;</span> 
</span></span><span style="display:flex;"><span>    storage <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;local-lvm2&#34;</span>
</span></span><span style="display:flex;"><span>    target_node <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;proxmox&#34;</span>
</span></span><span style="display:flex;"><span>    unprivileged <span style="color:#f92672">=</span> true
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span></code></pre></div><h4 id="run">Run</h4>
<pre tabindex="0"><code>terraform init
terraform plan
terraform apply
</code></pre>]]></content:encoded>
    </item>
    
    <item>
      <title>Remove Proxmox 5.4 &#34;No Valid Subscription&#34; message</title>
      <link>https://andrewbeaton.net/posts/2019/09/proxmox-no-valid-subscription/</link>
      <pubDate>Sun, 29 Sep 2019 00:00:00 +0000</pubDate>
      
      <guid>https://andrewbeaton.net/posts/2019/09/proxmox-no-valid-subscription/</guid>
      <description>Remove Proxmox 5.4 &amp;#34;No Valid Subscription&amp;#34; message</description>
      <content:encoded><![CDATA[<p>If, like me, you are using Proxmox in your Homelab, it can get a bit annoying to see the “No valid Subscription” message, every time you log in.</p>
<p>Purchasing a subscription from Proxmox is certainly recommended if you’re planning to use it in anger or in a production environment as it will give you access to support, the enterprise repository and keep the developers supported.</p>
<p>But for a test environment, you can remove the message by simply editing one of the JavaScript files on the server.</p>
<p>This file does get overwritten when you update, so you will need to reapply when that happens.</p>
<h2 id="detailed-approach">Detailed Approach</h2>
<pre tabindex="0"><code>cd /usr/share/javascript/proxmox-widget-tookit
cp proxmoxlib.js proxmoxlib.js.old
vi proxmoxlib.js
</code></pre><p>Search for Active until you find it in the following line:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-JavaScript" data-lang="JavaScript"><span style="display:flex;"><span><span style="color:#66d9ef">if</span> (<span style="color:#a6e22e">data</span>.<span style="color:#a6e22e">status</span> <span style="color:#f92672">!==</span> <span style="color:#e6db74">&#39;Active&#39;</span>) {
</span></span></code></pre></div><p>And change it to:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-JavaScript" data-lang="JavaScript"><span style="display:flex;"><span><span style="color:#66d9ef">if</span> (<span style="color:#66d9ef">false</span>) {
</span></span></code></pre></div><p>Save the file and exit. Now restart the service to load the updated file:</p>
<pre tabindex="0"><code>systemctl restart pveproxy.service
</code></pre><h2 id="one-liner-approach">One Liner Approach</h2>
<pre tabindex="0"><code>sed -i.bak &#34;s/data.status !== &#39;Active&#39;/false/g&#34; /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js &amp;&amp; systemctl restart pveproxy.service
</code></pre><p>Even if you are feeling brave, I would recommend that you take a backup of proxmoxlib.js file before running the above command, just to be safe.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
