pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

20210305-the_usefulness_of_drist.md (2390B)


      1 In work we use Ansible for configuration management and various scheduled check (through AWX).  I am a big fan of Ansible and have written plenty of {roles,playbooks} to help manage our Linux infrastructure.
      2 
      3 Occasionally though I may need to run a check on a system, or maybe gather some data.  Running a single bash command or a small script can be far quicker than writing an Ansible playbook.  To do this on multiple systems I use to pass commands to ssh in a for loop, but this can become cumbersome.
      4 
      5 Recently I was introduced to `drist`.  Like Ansible it is a "tool to configure and synchronize configurations to servers", and uses `ssh` to access the systems.  Unlike Ansible it uses simple shell scripts and `rsync`.
      6 
      7 You can download `drist` from bitreich.org
      8 ```
      9 git clone git://bitreich.org/drist/
     10 ```
     11 
     12 The repository comes with plenty of examples to get you started.
     13 
     14 If you have a file called "script" in your $PWD you can run it against a single system
     15 ```
     16 drist user@hostname
     17 ```
     18 
     19 Or add a list of hostnames to a file, called "servers" for example, then incant
     20 ```
     21 drist servers
     22 ```
     23 
     24 It is encouraged for you to have ssh keys configured on your servers, otherwise you will be prompted to enter your password multiple times for each system.
     25 
     26 An example script could be as simple as gathering some basic information
     27 ```
     28 hostname
     29 uname -r
     30 cat /proc/loadavg
     31 who
     32 ```
     33 
     34 We can then incant `drist <hostname>`
     35 ```
     36 Running on blacksun
     37 Executing file "script":
     38 blacksun
     39 4.9.0-8-amd64
     40 0.00 0.00 0.00 1/92 21836
     41 pyratebeard pts/0        Sep 23 10:06 (mosh [12511])
     42 ```
     43 
     44 You can also copy up files and then use the script to carry out any actions required.  For example, lets say we want to set a new MOTD on our servers.  Create a directory called "files" and then under that directory add a new MOTD file
     45 ```
     46 .
     47 ├── files/
     48 │   └── motd
     49 └── script
     50 ```
     51 
     52 Our script now looks like this
     53 ```
     54 sudo mv ./motd /etc/motd
     55 sudo chown root:root /etc/motd
     56 sudo sed -i 's/^PrintMotd\ no/PrintMotd\ yes/' /etc/ssh/sshd_config
     57 sudo systemctl reload sshd
     58 ```
     59 
     60 We move the MOTD file to /etc and change ownership to root.  Make sure we have PrintMotd enabled in sshd_config and reload the service to pick up any changes.
     61 
     62 These are some very basic examples but hopefully you can see how quick and easy it is to use, especially for small tasks were Ansible might be considered overkill.