Tuesday, February 27, 2018

Grep returning if results were found or not

Today I needed a one-liner like this to help with with an Ansible playbook, storing here for posterity:

rpm -qa | grep -q "rhn" && echo 'is installed' || echo 'not installed'

Ansible: Part Three

So at work I'm tasked with hardening the new Wildfly environment which consists of 1xdev, 2xuat and 4xprod servers.

I *had* plans on using this as an opportunity to pound our some Python but after a learned recommendation from a friend in IRC I went the Ansible route and boy am I glad I did!
I can't quite recall what happened last year when I tried and failed twice.. but yesterday I had a simple ping command working and hitting all 7 servers within an hour's time.  Last night I banged out half a dozen cursory playbooks within 4 hours and today I've got a working couple of playbooks that are furthering me to my goal of World Domina.. err automating the things.

Wednesday, February 7, 2018

SCP files thru multiple proxy hosts

I realize this might be old-hat for quite a few but I just learned it and this will save me so bloody much time!

While there are multiple ways of doing this.. including editing your .ssh/config file to include a similar reference I am choosing the full CLI method.

So first off make sure netcat (nc) is installed on all hosts.  Then craft a string as such:

scp -o ProxyCommand="ssh first_host nc second_host 22" /local/path/to/file user@target_host:/dest/path


So what I have done here is to ssh proxy through host1, to host2 then scp'd from host2 to target_host.  Which in my case was exactly what I needed since this new Java environment requires me to jump through two proxies to reach my target.

Like I said I know this is old stuff to a large percentage of you Unix/Linux admins but hopefully this will help someone.