Make Ansible Playbook Distribution Agnostic

I’ve been thinking about switching to a rolling distribution on my working machine for quite some time. Because the packages in Ubuntu repositories are just too outdated for my needs and I want to save myself the headache of PPAs. And when Ubuntu announced dropping Unity in favor of Gnome, my mind was made up. I would use a rolling distro on my main computer and Ubuntu 16.04 elsewhere.

Unify package installation

In the end, I decided to go for OpenSuse. Since I use an Ansible playbook to setup my machines, it would take no time to have it up an running. Or so I thought. However, there was a little caveat. As my playbook used the apt module to install software, it would obviously not run on OpenSuse. Luckily, since the version 2.0, Ansible provides a platform-agnostic package manager module. It is called simply package. As a result, installing packages across different distributions is as easy as running:

---
- name: Install packages
  become: yes
  package:
    name: git
    state: present

Or is it? While it may work in the case of Git, not all packages have a same name in different Linux distributions. So you have to set up variables for those: First of all, defaults in vars/default.yml:

apache_package: apache2

Then, for Debian family vars/Debian.yml

---
apache_package: apache2

And for Redhat family vars/Redhat.yml

---
apache_package: httpd

Afterwards, just include them in your tasks:

 - include_vars: "{{ item }}"
   with_first_found:
     - "{{ ansible_os_family }}.yml"
     - "default.yml"

 - name: Install Apache
   become: yes
   package: name: "{{ apache_package }}"
   state: present

Read more…

Powerfish Gets New Features and Support for Themes

I dedicated couple evenings to Powerfish lately, resulting in a host of new features. If you don’t know what I’m talking about, Powerfish is an elegant and informative prompt for the Fish shell inspired by Powerline. Without further ado, let’s see what is new.

New features

First of all, Powerfish now fully supports the Vi keybindings. So there is no ugly box showing the current mode at the beginning of the prompt anymore. A small change, but definitely visible, if you use the Vi mode, like me. There are also two new flags in the prompt. One displays the number of background jobs, and another one shows if the last command failed. The Git flags were overhauled as well. Now they show number of untracked, modified, staged, stashed and conflicting files. If you don’t care about the concrete numbers, there is an option to display only the flags.

Read more…

Setup Mosh - SSH’s Cousin for Mobile Era

SSH, while an indispensable tool, is starting to show its age in certain situations. We have all experienced the lag when using cell phone tethering or finding your remote connections hanging in limbo when resuming your laptop from sleep. No wonder - the first release of SSH came out over twenty years ago and the landscape was very different back then. It was an age of desktop workstations and cable networks. When SSH was designed, nobody thought people would be working on laptops, switching between wifis and mobile connections. Mosh - short for mobile shell - aims at those users. It uses state machines on both client and server and only communicates the changes between them, lowering bandwith use and decreasing latency. It uses SSH for authetification, which greatly simplifies its setup. Once the connection is established, it communicates through encrypted UDP datagrams, which makes it more resilient to IP address changes and connection dropouts. As you can see, it is a handy tool to have when you are on the go. So how to get it running?

Install

Mosh needs to be installed on both the server and the client. In most package managers, the package is called simply mosh. For example, on Debian and Ubuntu derived systems, you can install it with:

$ sudo apt install mosh

Read more…

Set Up Password-less SSH Login and Secure Your SSH

You have Raspberry Pi set up and running, but typing password every time you try to login using ssh is quite the pain. Well, using key-based authentication is not only more convenient, but also more secure. Let’s see how to set it up.

Set up password-less SSH

First of all, you need to generate the public / private key for your computer using this command:

$ ssh-keygen -t rsa -b 4096

You will be asked for a pass-phrase. Using one is highly recommended. You should use one that is long, preferably a whole sentence, and different from your password. Avoid using famous quotes, as your pass-phrase could easily get cracked by a dictionary attack. Next, upload the key to your Pi:

$ ssh-copy-id -i ~/.ssh/id_rsa.pub pi@raspberrypi.local

If it failed to connect, just use the Pi’s ip adress in place of rapsberrypi.local. You should now be able to connect to your pi using the key.

Read more…

Raspberry Pi Wifi Setup in Couple Steps

Say, you might have finished configuring your Raspberry Pi. It is running smoothly, but there one thing that gets on your nerves. The pesky ethernet cable is getting in your way. Well, it’s time to get rid of it for good and setup the wifi. To do that, you need to edit the following two files: /etc/network/interfaces and /etc/wpa_supplicant/wpa_supplicant.conf.

Configure the wireless

Let’s start with the network intefaces. Open the first file in text editor:

$ sudo nano /etc/network/interfaces

Go to the wlan0 section, which stands for you wifi adapter, and edit it so it looks like this:

allow-hotplug wlan0
iface wlan0 inet dhcp
  wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

In case your /etc/network/interfaces does not include a wlan0 section, just copy the whole thing. When you are done, press ctrl + x to save the changes.

Read more…

Change Raspberry Pi Password, Username and Hostname

Rapsberry Pi is the single most popular computer in the world. And it is easily one of the most hacked systems as well. That’s due to single fact - most users never change the default username and password. But is a relatively a simple process, so there is no reason not to do it. If you already have your Raspberry Pi up and running, you can get going.

Read more…

Powerfish - an Elegant and Informative Prompt

Please, all welcome Powerfish, the one true Fish prompt to rule them all. I know what you might be thinking: “Custom shell prompts? I am not that much of a geek.” I was like that too. But then I thought, what if instead of just taking up space, the prompt could show me the information I need? Powerfish does just that and looks good too. No more wasting time typing ‘git status’, having to amend commits and similar annoyances. But enough words, just see it in action:

Powerfish - an elegant Fish prompt

You might have noticed similarities with Powerline. And you would be right. When I was looking for a nice Fish prompt (to no avail), Powerline inspired me to write one instead. To get Powerfish, just head over to the project Gitlab page. Not using Fish shell yet? No need to worry, check out why it’s so awesome and go install it.

Website Obesity

The other day, I stumbled upon an interesting talk by Maciej Cegłowski about the worrying trend of website obesity. I have to say, I fully agree with him. As it stands, the situation is getting quite ridiculous. Designers and web coders should stop the unnecessary bloat. Here’s the transcript of the talk:

Website Obesity

Protect Your Eyes From Computer Eye Strain

Internet has revolutionized our lives. It has changed the way we work, communicate and access information. But as we spend ever more time in front of shining computer and phone screens, our eyes pay the price. We are plagued with near-vision, eye strain and other problems. Allow me to introduce two tools, that can help in relieving the computer eye strain.

Eye excercizes with SafeEyes

We typically watch screens from very close distances, trying to read the tiny letters. That is the biggest culprit behind computer eye strain, because our eyes have simply not evolved for that. So, a collection of techniques called eye yoga were developed to battle eye fatigue. But as with anything, it is easy to forget about them, while you are concentrating on other stuff. Fear naught, SafeEyes comes to save the day. It’s a simple app, that sits in the taskbar and every once in a while reminds you to take a break, suggesting an eye yoga exercise. Kind of like EyeLeo for Mac. It is intelligent enough not to pop up while you are watching a movie. And you can skip a break, if you need to, so it is fairly unobtrusive.

Read more…

Automatically Setup Your Computer with Ansible Playbook

Setting up a computer can be a major annoyance. Being ‘the tech guy’, I still have vivid nightmares of spending every other weekend reinstalling friends’ and family members’ Windows boxes that have come to a crawl. Now, most of us know enough to backup the important data and that makes the process easier. (If you don’t have backups, go setup Nextcloud, Syncthing, or some other automatic system. Seriously, it’s gonna come back to bite you sooner or later.) But there is still the matter of installing and configuring all your software. Some people have tackled that by writing install scripts. However, there is a better way - Ansible playbook. Let me introduce Ansible. Ansible is a software for computer provisioning. In computing, provisioning means automated installation and configuration of software and services. Provisioning tools, such as Ansible, Chef and Puppet, help you cut down the setup time from hours to mere minutes. Their main advantage over custom scripts is that they are idempotent. That means they only makes the necessary changes. So, if a task fails (for example because ou forgot to connect your Ethernet cable, oops), you can just run it again without any worries. The reason I chose to use Ansible, is that the tasks are easily configurable using yaml files. It is also written in Python, which makes it easy to write your own module for it, in case of need. So what is Ansible playbook? It is the collection of yaml files, describing the tasks to be executed. You can find an introduction to its syntax in Ansible documentation. I will demonstrate how you can setup your computers using an Ansible playbook, using mine as an example. You can find it at my Gitlab page.

Read more…