Automating SSH keys loading for Ansible usage

For using Ansible it’s required to have a working set of ssh-keys already deployed. If you get a set of systems that have not been provisioned by you and are missing the SSH keys, having it fixed might take a while if doing it manually. Good news is that you can use a script in expect to cover this part: #!/usr/bin/expect -f # set Variables set password [lrange $argv 0 0] set ipaddr [lrange $argv 1 1] # now connect to remote system spawn ssh-copy-id root@$ipaddr match_max 100000 # Check for initial connection (add key of host) set timeout 5 expect "yes/no" { send -- "yes\r" } # Check for password prmpt set timeout 120 # Look for passwod prompt expect "password:" { send -- "$password\r" } # send blank line (\r) to come back send -- "\n" expect eof This script, when used like:...

March 2, 2023 · 2 min · Pablo Iranzo Gómez

[python] Generate ranges from items

Some years ago, I added a script for updating headers for (C) in the python files I was developing for Risu. In this way, the header got the list of authors and years working on the files updated automatically. With the pass of the years, the list started to became a bit too long, so I worked on creating code for getting ranges instead. This is the code I used:...

November 25, 2022 · 2 min · Pablo Iranzo Gómez

Automate code build and deployment with ansible

Let’s say that we want to keep our system updated with some code which is not distributed as a regular package, but as a code in a repository (which unfortunately, it’s a pretty common situation). As a part of the ansible playbooks used for the hosts, I can add a snippet like this: gitrepos: - { url: "https://github.com/myrepo/repo.git", tag: "tagtocheckout", folder: "/root/path-for-check-out", chdir: "subdir to enter", build: "make build", exec: "build/mybuiltbinary", } With this definition in the host inventory, we can then in our playbook to perform several steps:...

November 9, 2022 · 3 min · Pablo Iranzo Gómez

OpenShift's oc debug and parallel execution

A colleague reported some issues in the OpenShift troubleshooting and diagnosis scripts at OpenShift-checks. Some time ago I did contribute some changes to use functions and allow using the RISU wrapper to the scripts, helping consuming the results via RISU’s HTML interface. As my colleague reported, for some plugins, the output of the command was not shown in the HTML Interface. After some investigation, it was found that parallel execution for the plugins was causing no output to be shown, but when filtering to individual ones via risu -i XXXXXXX/plugin -l it was working fine… the problem was not the check itself, as both of them worked fine when executed individually but failed when executing them together....

November 3, 2022 · 2 min · Pablo Iranzo Gómez

Ansible - dynamically include Jinja templates and tasks

For my ansible playbooks, I wanted to be able to add several new templates to be copied to target system, and additionally be able to perform some commands for them without having to specify each individual file/template to copy. My approach: Define for the hosts I want to find templates/playbooks define a var named extras for the relevant hosts: extras: - ntp - certificates The names defined (in above example ntp and certificates) are just name of folders laying inside tasks/templates/${folder} that are searched and included or excluded based on extras values....

September 24, 2022 · 2 min · Pablo Iranzo Gómez
This blog is a participant in the Amazon Associate Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.