network automation blog
-
Adding directories to $PATH safely
$PATH is an environment variable containing a list of directories where executable programs are located in UNIX systems. The shell will search for executables in directories separated by the colon punctuation from left to right until it finds a match. A typical scenario is to add ~/.local/bin as the first directory in $PATH, so you…
-
Installing Python from source
The Ansible Control node requires a relatively new version of Python (see matrix here), often newer then the one your OS relies on. For example, the default Python implementation in RHEL 9 is Python 3.9, while ansible-core 2.17 requires Python 3.10 or higher for the Ansible Control Node. Sometimes you can install a newer version…
-
Faster Vim window navigation
Vim does two things when you open a file: Like Tmux, Vim allows us to split windows and navigate between them. By splitting a window, you are technically duplicating the current buffer. Here are the commands to split windows vertically and horizontally, respectively: The commands for switching between windows are: I like to remap the…
-
Quick automation in Vim with macros
A macro lets you record a sequence of commands to a registry. The macro can be replayed with the following command (once by default). You can view the macro using the reg command. Finally, these commands will edit the macro in a new buffer. Example Consider the following file. Suppose we want to move each…
-
Running Ansible Playbooks safely
A good way to explicitly and dynamically control which inventory hosts or groups a playbook executes against is by defining the host’s field in the playbook as a variable, commonly named “target”. This variable is then defined as an extra vars each time you run the playbook, and if you forget it the playbook will…
-
Neovim vs Vim
I started in Vim, but after a while, I replaced Vim with Neovim. I find that Neovim has more sensible defaults, “looks” better, and has good Language Server Protocol (LSP) integration and syntax highlighting plugins. I also prefer the Lua configuration setup in Neovim compared to Vim and Vimscript, even though I don’t do a…
-
Basic Vim movements
These are pretty much the keys I use to move around in Vim (or Neovim). Key Explanation h Move the cursor left. j Move the cursor down. k Move the cursor up. l Move the cursor right. gg Go to the first line of the document. G Go to the last line of the document…
-
Essential Tmux commands
Tmux is a terminal multiplexer and I can’t imagine working in a terminal without it. Here is a list of commands I most frequently use. Please note that the “prefix” will depend on your Tmux dotfiles (the default is ctrl+b). Command Explanation tmux ls List active sessions. tmux new -s example Create and connect to…
-
Ansible Navigator intro
Ansible Navigator is a text-based command-line version of AAP/AWX (with some limitations), and I use it to test and troubleshoot newly created execution environments. Ansible Navigator can be installed with pip. Once installed, create an ansible-navigator.yml configuration file, and point to the execution environment image, along with your inventory and ansible.cfg file. Then run a…
-
Useful Ansible commands
Table with Ansible commands I use often: Command Explanation $ ansible-playbook playbook.yml -i ~/inventory/production -e “target=host1” Run a playbook with some common options. $ ansible-vault encrypt_string ‘secret’ –name ‘foobar’ Encrypt a variable. $ ansible localhost -m debug -a var=’foobar’ -e ‘@inventory/group_vars/all/foobar.yml’ Decrypt a variable. $ ansible-inventory –list -i ./inventory/production Parse the inventory. $ ansible-galaxy collection…