Getting Started with Go


I’m working on some automation tasks and will be using golang to consume a RESTful API and generate reports on data. I’ve already had vscode installed on my personal computer but I also had a few things to do to get my environment set up for learning and iterating. For my full-time job I work using Mac OS and my PC is a Windows machine for gaming; this is the first blog post I’ve written from my PC!

Setting up VCS

Through the powerful features offered by the git version control system (VCS) I will be able to keep a public log of my golang areas of interest as well as use private repositories to solve problems and complete tasks. I installed Git for Windows with the option to also install git bash for Windows. I’m interested in seeing how compatible all of this is with the Windows Subsystem for Linux – which I love using!

Setting Up Repos

I added a new public repo called hello-go where I will document some of the tutorial code I find in a place where I can play around with it.

I also added a new private repo for code related to my automation task.

What’s Coming Up

C Spire Business is bringing back its premier tech event Bytes & Bites in Birmingham, AL (and beyond!) on 21 October 2021. If you’re a business or IT leader register now for this free event.

green pepper plant photo from 30 Sept


Authored by Michael Lamb.
Published on 01 October 2021.
Category: Golang


Ansible Installation


What is Ansible?

Ansible is an IT automation tool provided by RedHat. It is designed to operate agentless, which means that nodes don’t need separate agent applications to be used in an Ansible automation.

Ansible runs playbooks which execute a series of tasks on a given set of hosts. Tasks are performed in order. It is supposed to be easy to use and understand so that anyone in an IT organization can read a playbook and know what it is doing.

Why do I want to learn Ansible?

There’s a number of reasons why, rooted generally in the use cases Ansible is known for:

  • Configuration management
  • App deployment
  • Provisioning
  • Continuous delivery
  • Security & compliance
  • Orhcestration

Ansible Concepts

  • Control node : any machine with Ansible installed
  • Managed nodes : any network device / servers managed with Ansible
  • Inventory : a list of managed nodes
  • Collections : distribution format for Ansible assets (playbooks, roles, modules)
  • Modules : the units of code Ansible executes
  • Tasks : the units of action in Ansible
  • Playbooks : ordered lists of tasks

Getting Started with Ansible

Installation

I refered to the latest Ansible community installation guide to figure out what I needed to do to get the tool working on my cluster.

Because Ansible is agentless, I only need a single control node to be able to run playbooks or ad-hoc tasks on managed nodes.

I installed Ansible on node1 using the system package manager

sudo apt-get install ansible

Creating an inventory

Ansible allows users to define lists of hosts as inventory.

On node1 I opened /etc/ansible/hosts which is the file containing the hosts I want to run playbooks on and added my cluster. This file has examples of how to add inventory. Following one of those examples resulted in this straightforward definition of my cluster.

[cluster]
node[1:6]

Let’s run a task!

At this point I am ready to see whether Ansible is set up and working properly.

ansible all -m ping

This runs the ping module against all hosts in inventory.

As depicted below, all the hosts were successfully pinged!

screenshot of console showing Ansible output

Conclusion

I’ve got a control node ready to execute playbooks on the cluster.

The only other cluster-related topic I want to delve into now is Kubernetes, so that is what I’ll be working to set up this week.


Authored by Michael Lamb.
Published on 28 March 2021.


Workspace Configuration


Managing Remote Access

Yesterday’s post included a reminder that when setting up a new Pi it is important to change the default password of the pi user. In most distributed computing environments is it also best practice to create individual user accounts to manage access to the various nodes on the network.

My preference is to have a user that can access each node without needing to type a password. This is accomplished with our favorite remote access tool SSH.

Passwordless SSH access

I followed the steps outlined below with reference to this guideline from the RPi Foundation.

1. Create a new user on each node and switch to it

As the pi user I can set up a new user for myself.

sudo adduser michael
sudo usermod -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,gpio,i2c,spi michael

michael then has permission to act as a sudoer, so I finished the rest of my work on the node logged in as this user using su (swtich user).

sudo su - michael

2. Finish raspi-config as new user

sudo raspi-config

raspi-config brings up an interactive menu. Here I set the hostname and timezone.

3. Copy the workspace SSH public key to the node

From my main computer I use ssh-copy-id which will install my public key onto the node.

ssh-copy-id michael@node1

The resulting output:

Number of key(s) added:        1

Result

Following this process on each node makes it easy to use my main computer as a workspace and perform tasks. Now that I can connect to each node individually, my next goal is to install Ansible and dive into what sort of automations I can tinker with.

Additionally, because I know Ansible only needs to be installed on one node and its agentless operation requires SSH access, I have also generated an SSH key on node1 and copied the ID to all the other nodes so that Ansible will be able to perform actions as michael.


Authored by Michael Lamb.
Published on 27 March 2021.



Michael Lamb is a software engineer for privately-held telecommunications and technology company C Spire, headquartered in Ridgeland, Mississippi. He is a resident of Jackson, Mississippi, with his two cats and many plants. He graduated from Mississippi State University with a bachelor of science in Software Engineering. He is happily employed full-time creating microservices using Java and Spring technologies but is open to consulting.
© Copyright 2021