Ansible Playbook for upgrading Ubuntu based Nagios Server to latest version

Hello. This is a typical Ansible playbook code to upgrade your Nagios Server to the latest version (4.4.2, announced August 2018).
It has been tested with Ubuntu 16.04.4 LTS for the Nagios Server, OpenSuSE 42.3 and Ansible 2.6 for the Ansible server.
It is presumed that you have previously installed Nagios using source code, preferably with a 4.x version (upgrading from 3.x is different).
If you are new at this I suggest you go through the process manually at least once. Start here: but be mindful because the process described there is too generic. Depending on what you needed to activate on your nagios server, you may need different options and additional steps.
If you are not new at this, you can take the playbook and modify it to suit your needs.
I am in no way responsible if you damage your system by applying commands that were not suited for it. Backup your system first, or take a snapshot if you are using Vmware as a platform (remember to remove it later if everything goes well, vmware snapshots are not equivalent to backup!).
You can replace nagiosserverhostname with yours, as it is declared in your ansible host files. Start here:
You will need to know the basics of how to install Ansible, create a list of your servers and run the playbook.
I intend to polish my Full Nagios Core Installation guide (Core Server, Nagios Plugins, extra plugins, Nagios Graph etc) and publish it as well, and then create a Playbook for creating such an installation from scratch with Ansible. The last part is not ready yet. Perhaps I will get to update my notes for Ubuntu 18.04 LTS but as the season is picking up pace, I may have little time to spare for it. I will do my best.
I am sorry I can’t allow comments on this site, the spam is too much to handle. You can look me up on twitter and ask there.
There you go, I hope you find it usefull!
Don’t forget, it’s YAML syntax so indents are important plus other things you can read when you learn about Ansible.

- hosts: nagiosserverhostname
- name: get rid of old installation dir
path: /tmp/nagios
state: absent
- name: get rid of old installation archive
path: /tmp/nagios.tar.gz
state: absent
- name: download and uncompress
shell: cd /tmp;rm nagios*.tar.gz;wget -O nagios.tar.gz;tar -zxf nagios.tar.gz;mv nagioscore-nagios-4.4.2 nagios
- name: change dir to /tmp
shell: cd /tmp/nagios;./configure --with-command-group=nagcmd --with-mail=/usr/sbin/sendmail --with-httpd-conf=/etc/apache2/;make all;make install;make install-init
- name: check configs syntax
shell: /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
- name: restart nagios service
name: nagios
state: restarted
- name: get rid of old installation dir
path: /tmp/nagios
state: absent
- name: get rid of old installation archive
path: /tmp/nagios.tar.gz
state: absent

Blog maintenance

I was forced to update my blog and delete a few old posts as I am preparing to post some work related (IT) material in twitter pointing here.
Most deleted posts concern old work interests and World of Warcraft links.
The material to be posted will be about Nagios, Ansible, and Automation in general.

Εγκατάσταση Nagios 4.1.0 σε Ubuntu Server 14.04.3 LTS με plugins, check_nrpe, check_esxi_hardware και nagiosgraph

Σήμερα έπιασα ξανά το θέμα του upgrade σε Nagios 4 και έμαθα ότι στις 18/8 (χθες) βγήκε το Nagios 4.1.0 stable.

Ξεκίνησα (μετά από δοκιμή για upgrade) ένα clean install στον ubunagios03 με εγκατάσταση από την αρχή του Ubuntu Server 14.04.3 LTS και nagios core 4.1.0 & nagios plugins v.2.1.1

Πρώτα ενεργοποίησα το χρήστη root με sudo passwd root.

Μετά με το χρήστη root ενεργοποίησα το ssh login για το root κάνοντας edit στο /etc/ssh/sshd_config το PermitRootLogin σε yes.

Για την εγκατάσταση βρήκα διάφορα strings για τα προαπαιτούμενα αλλά αυτό που τελικά χρειάζεται είναι το :

apt-get install wget build-essential apache2 apache2-utils php5-gd libgd2-xpm-dev libapache2-mod-php5 libssl-dev zip


useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data


Κάνουμε μεταφορά των tar.gz των core & plugins στο /usr/local/src.

tar -zxf nagios-4.1.0.tar.gz
cd nagios-4.1.0/

./configure –with-nagios-group=nagios –with-command-group=nagcmd –with-mail=/usr/sbin/sendmail –with-httpd_conf=/etc/apache2/conf-available

Στη συνέχεια:

make all

make install

make install-init

make install-config

make install-commandmode

make install-webconf

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Πάμε για τα plugins
cd ..
mv /tmp/nagios-plugins-2.1.1.tar.gz ./
tar -zxf nagios-plugins-2.1.1.tar.gz
cd nagios-
cd nagios-plugins-2.1.1/
./configure –with-nagios-user=nagios –with-nagios-group=nagios –enable-perl-modules –enable-extra-opts
make install

Ενεργοποιούμε το cgi module στον Apache2

a2enmod cgi

Δημιουργούμε password για το χρήστη nagiosadmin για την πρόβαση στο nagios gui.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Ανοίγουμε το παρακάτω αρχείο

vim /etc/apache2/sites-enabled/000-default.conf

Και προσθέτουμε την εξης γραμμή:

Include conf-available/nagios.conf

Κάνουμε restart το apache2 service και ενεργοποιούμε το nagios service.

service apache2 restart
service nagios start

Έτοιμο το βασικό κομμάτι του Nagios. Έχουμε όμως και ένα αριθμό από plugins.

Συγκεκριμένα χρειαζόμαστε το Check_NRPE, το Check_esxi_hardware και το nagiosgraph.

Για το check_nrpe πρέπει εγκατασταθεί το nrpe αλλά μόνο το κομμάτι του plugin (όχι ο server). Έτσι κατεβάζουμε το NRPE από το sourceforge (έκδοση 2.15 εδώ και δύο χρόνια) και το αποσυμπιέζουμε:

 mv /tmp/nrpe-2.15.tar.gz /usr/local/src
cd /usr/local/src/
tar -zxf nrpe-2.15.tar.gz
cd nrpe-2.15/


 ./configure –with-ssl=/usr/bin/openssl –with-ssl-lib=/usr/lib/x86_64-linux-gnu
make all
make install-plugin

To plugin check_nrpe είναι έτοιμο για χρήση.

Το check_esxi_hardware το κατεβάζουμε από το nagios exchange.

Στη συνέχεια:

mv /tmp/ /usr/local/nagios/libexec/
chown nagios:nagios
chmod g+w

Κανονικά χρειαζόταν εγκατάσταση και downgrade του pywbem. Τώρα απλώς εγκαθιστούμε:
apt install python-pywbem

Έτοιμο το plugin.


Copy & Paste with vim

These are the sources:

Since you already know how to cut/yank text, here are a few ideas for pasting it back into another file:

  • Edit the first file, yanking the text you want. Then open your second file from within vi (:e /path/to/other/file) and paste it
  • Open both files together in a split window and navigate between them using Ctrl + w, Up/Down either by:
  • vi -o /path/to/file1 /path/to/file2
  • From within the first file, Ctrl + w, s

from the third link:

The ability to duplicate text in an editor can be handy. vi and vim have several useful copy and paste commands.
The command ‘Y’ or ‘yy’ copies (yanks) one or more lines. To copy one line, two lines, 10 lines, and all lines to the end of the file, respectively:

Y 2Y

To paste the text contained in the buffer above (uppercase P) or below the current cursor position (lowercase p), respectively:

P p

It is also possible to yank text within a line. The following commands yank text from the current cursor position to the end of the word and the end of the line, respectively:

yw y$

The same commands paste the text within a line. Lower case p pastes after the cursor position and upper case P pastes before.

Paste will also work with deleted text, either lines or parts of lines. Be careful not to execute any other commands prior to pasting as this will empty the buffer.

 from the second link

Visual selection, although common in applications today, is a key feature that differentiates vim from traditional vi.

To cut (or copy) and paste using visual selection:

  1. Position the cursor at the beginning of the text you want to cut/copy.
  2. Press v to begin character-based visual selection (or upper case V to select whole lines, or Ctrl-v for a vertical block).
  3. Move the cursor to the end of the text to be cut/copied. (While selecting text, you can perform searches and other advanced movement, a feature that sets vim apart from most other editors.)
  4. Press d (as in “delete”) to cut, or y (as in “yank”, which I imagine meaning “yank so hard and fast that it leaves a copy behind”) to copy.
  5. Move the cursor to the desired paste location.
  6. Press p to paste after the cursor, or P to paste before.

In gvim, visual marking (steps 1-3) can be replaced by selecting text using a mouse or similar pointing device, although I strongly prefer to navigate using the keyboard.

Bonus tip: To replace the selected text with new text (to be entered by you), press ‘c’ instead of ‘d’ or ‘y’ on step 4. This deletes the selection and leaves you in insert mode. Then, instead of (or prior to) steps 5-6, type your replacement text.

Pasting over a block of textEdit

You can copy a block of text by pressing Ctrl-v (or Ctrl-q if you use Ctrl-v for paste), then moving the cursor to select, and pressing y to yank. Now you can move elsewhere and press p to paste the text after the cursor (or P to paste before). The paste inserts a block (which might, for example, be 4 rows by 3 columns of text).

Instead of inserting the block, it is also possible to replace (paste over) the destination. To do this, move to the target location then press 1vp (1v selects an area equal to the original, and p pastes over it).

When a count is used before v, V, or ^V (character, line or block selection), an area equal to the previous area, multiplied by the count, is selected. See the paragraph after :help <LeftRelease>.

Note that this will only work if you actually did something to the previous visual selection, such as a yank, delete, or change operation. It will not work after visually selecting an area and leaving visual mode without taking any actions.


NOTE: after selecting the visual copy mode, you can hold the shift key while selection the region to get a multiple line copy. For example, to copy three lines, press V, then hold down the Shift key while pressing the down arrow key twice. Then do your action on the buffer.

I have struck out the above new comment because I think it is talking about something that may apply to those who have used :behave mswin. To visually select multiple lines, you type V, then press j (or cursor down). You hold down Shift only to type the uppercase V. Do not press Shift after that. If I am wrong, please explain here. JohnBeckett 10:48, October 7, 2010 (UTC)

If you just want to copy (yank) the visually marked text, you do not need to ‘y’ank it. Marking it will already copy it.

Using a mouse, you can insert it at another position by clicking the middle mouse button.

This also works in across vim applications on Windows systems (clipboard is inserted)

This is a really useful thing in Vim. I feel lost without it in any other editor. I have some more points I’d like to add to this tip:

  • While in (any of the three) Visual mode(s), pressing ‘o’ will move the cursor to the opposite end of the selection. In Visual Block mode, you can also press ‘O’, allowing you to position the cursor in any of the four corners.
  • If you have some yanked text, pressing ‘p’ or ‘P’ while in Visual mode will replace the selected text with the already yanked text. (After this, the previously selected text will be yanked.)
  • Press ‘gv’ in Normal mode to restore your previous selection.
  • It’s really worth it to check out the register functionality in Vim: ‘:help registers’.
  • If you’re still eager to use the mouse-juggling middle-mouse trick of common unix copy-n-paste, or are into bending space and time with i_CTRL-R<reg>, consider checking out ‘:set paste’ and ‘:set pastetoggle’. (Or in the latter case, try with i_CTRL-R_CTRL-O..)

You can replace a set of text in a visual block very easily by selecting a block, press c and then make changes to the first line. Pressing <Esc> twice replaces all the text of the original selection. See :help v_b_c.

On Windows the <mswin.vim> script seems to be getting sourced for many users.

Result: more Windows like behavior (ctrl-v is “paste”, instead of visual-block selection). Hunt down your system vimrc and remove sourcing thereof if you don’t like that behavior (or substitute <mrswin.vim> in its place, see VimTip63.

With VimTip588 one can sort lines or blocks based on visual-block selection.

With reference to the earlier post asking how to paste an inner block

  1. Select the inner block to copy usint ctrl-v and highlighting with the hjkl keys
  2. yank the visual region (y)
  3. Select the inner block you want to overwrite (Ctrl-v then hightlight with hjkl keys)
  4. paste the selection P (that is shift P) , this will overwrite keeping the block formation

The “yank” buffers in vim are not the same as the Windows clipboard (i.e., cut-and-paste) buffers. If you’re using the yank, it only puts it in a vim buffer – that buffer is not accessible to the Windows paste command. You’ll want to use the Edit | Copy and Edit | Paste (or their keyboard equivalents) if you’re using the Windows GUI, or select with your mouse and use your X-Windows cut-n-paste mouse buttons if you’re running UNIX.

Double-quote and star gives one access to windows clippboard or the unix equivalent. as an example if I wanted to yank the current line into the clipboard I would type “*yy

If I wanted to paste the contents of the clippboard into vim at my current curser location I would type “*p

The double-qoute and start trick work well with visual mode as well. ex: visual select text to copy to clippboard and then type “*y

I find this very useful and I use it all the time but it is a bit slow typing “* all the time so I am thinking about creating a macro to speed it up a bit.

Copy and Paste using the System Clipboard

There are some caveats regarding how the “*y (copy into System Clipboard) command works. We have to be sure that we are using vim-full (sudo aptitude install vim-full on debian-based systems) or a vim that has X11 support enabled. Only then will the “*y command work.

For our convenience as we are all familiar with using Ctrl+c to copy a block of text in most other GUI applications, we can also map Ctrl+c to “*y so that in Vim Visual Mode, we can simply Ctrl+c to copy the block of text we want into our system buffer. To do that, we simply add this line in our .vimrc file:

map <C-c> “+y<CR>

Restart our shell and we are good. Now whenever we are in Visual Mode, we can Ctrl+c to grab what we want and paste it into another application or another editor in a convenient and intuitive manner.


vim search and replace commands

If you want to match something at the end of the line you need to use the $ character at the end of the string pattern. The following are taken from : 

Let’s start by looking at searches and doing search and replace operations within Vim. You can do a search in normal mode by using /searchstring . This will search forward through the file for searchstring . Likewise, running ?searchstringwill search backwards through the file.

After running a search once, you can repeat it by using n in command mode, or N to reverse direction.

When you want to search for a string of text and replace it with another string of text, you can use the syntax :[range]s/search/replace/. The range is optional; if you just run :s/search/replace/, it will search only the current line and match only the first occurrence of a term.

Most of the time, that’s not sufficient, so you can add a range like so:

:8,10 s/search/replace/g

In that example the range is from line 8 to line 10. I’ve also added the “global” option, which tells Vim to replace every occurrence on a line, and not just the first occurrence. Without adding g, your search will match only the first instance of a string in any given line.

Another way to specify the range is to enter visual mode and select the lines that you want to search, and then press : to enter command mode. To enter visual mode from normal mode, press v to select regular visual mode, or V for line selection, or Ctrl-v for block selection. Then select the range in visual mode and press :, followed by the search command you wish to use.

If you want to search an entire file, you can use % to indicate that as the range:


You may also wish to be asked for confirmation before Vim makes a substitution. To do this, add the confirm (c) option to the end of the search and replace command: :%s/search/replace/gc. When you run this search, Vim will give you a prompt that looks something like this:

replace with foo (y/n/a/q/l/^E/^Y)?

The “y” and “n” are self-explanatory, but what about the rest? To tell Vim to go ahead and replace all instances of the matched string, answer with a. If you realize that you don’t really want to make the changes, you can tell Vim to quit the operation using q. To tell Vim to make the current change and then stop, use l, for last.

^E and ^Y allow you to scroll the text using Ctrl-e and Ctrl-y.

Where you land

Searches in Vim put the cursor on the first character of the matched string by default; if you search for Debian, it would put the cursor on the D. That’s usually fine, but Vim has a few options for offsetting the cursor placement from the beginning of the matched string.

To land on the last character in the matched string, rather than the beginning, add an /e to your search:


That will place the cursor on the n rather than the D. Vim also allows you to specify a cursor offset by line, or from the beginning or end of the string. To have the cursor land two lines above a matched string, for example, use /string/-2. To place the cursor two lines below the string, use /string/+2.

To offset from the beginning of the string, add a /b or /s with the offset that you want. For example, to move three characters from the beginning of the search, you’d use /string/s+3 or /string/b+3 — “s” for “start” or “b” for “begin.” To count from the end of the string, use /e instead, so /string/e-3 will place the cursor on the third character from the last character of the matched string.

Next: Vim’s special characters

Now that we’ve got basic search syntax covered, it’s time to look at some of Vim’s special characters to make searches a little more efficient. Searching for a literal string is out of the question if you’re trying to match every URL in a file, or every comment in a bash or Perl script.

The first character you want to get to know is the humble dot. In a search, a dot or period (.), will match any single character. Do a quick search using /. and you’ll see that it matches, literally, everything — letters, numbers, whitespace, the whole kit and kaboodle.

What if you want to match a term at the beginning or end of a line? Vim uses the caret to match the beginning of a line (^) and the dollar sign to match the end of a line ($). For instance, to find any line in a bash script that begins with a comment, you could use ^#. To find empty lines, just use ^$ which will match any line without any characters.

To match whitespace, use the \\s operator. If you wanted to find empty lines that contain nothing but whitespace, you could use ^\\s.*$. This will match lines with whitespace, but no other characters — it won’t match empty lines without white space. By contrast, the \\S operator will match non-whitespace characters.

The \\d operator will match any digit in a search, while the \\D operator will match any non-digit in a search. To match any uppercase character, use \\u, while \\l will match any lowercase character. Using \\U will match any non-uppercase character, and \\L will match any non-lowercase character.

There’s a subtle difference between matching any lowercase character and matching any non-uppercase character, and matching any uppercase character and matching any non-lowercase character. If you use \\u it will only match an uppercase letter — but if you use \\L it will match any uppercase letter and any other character that’s not a lowercase character; so it would match whitespace, digits, punctuation, and so on.

What happens when you actually want to search for a special character, such as a dollar sign or caret? Special characters can be escaped with the backslash character, so use \\$ to search for a dollar sign in your file, or \\^ to search for the caret, and so forth. Note that the backslash character is itself a special character, so you’d need to use two backslashes together.

You also may wish to delineate search terms by word boundaries. Say you do a search for sig using Vim. This will match sig, signature, signing, and a number of other strings that you do not wish to match. It might seem like a good idea to include spaces on each side of the search term, like so:

s/ term / replace /gc

That will do a better job of matching the search string only, but it will miss the string if it’s at the end of a sentence, or separated by a comma. To make sure you’re getting the right match, use \\ to match the end of a word. So, the search phrase would be better written as:


Quantity counts

If you’re lucky, your parents taught you at an early age not to be greedy. That’s a good rule in life, and usually a good rule in searching and replacing using Vim as well.

Vim allows you to specify how many of something you wish to match by adding quantifiers to the term. Some of the quantifiers are considered “greedy” because they match as many of the specified characters as possible. Others are non-greedy because they match a specific number or as few as possible.

As an example, the * quantifier tells Vim to match 0 or more of a character. So, a search like /abc* will match abc, abby, and absolutely.

To match one or more, use the \\+ quantifier. A search for /abc\\+ will match abc, but not abby or absolutely. For zero or one, use \\=, which would match abc, abby, and absolutely.

Vim can be even more precise, and will allow you to specify an exact number or range. The syntax for this is \\{0,10}, where the search would match 0 to 10 instances of the character. For example, to match a string with at least five uppercase characters, but no more than seven, you could use /\\; this breaks down as “match the beginning of a word, then five to seven uppercase characters, then the end of a word.”

If you want to match a number of characters exactly, use \\{n} where n is the number. Want to find all of the three-letter words in a file? Use /\\ and you’ll find every three-letter string in the file. Of course, that might match non-word strings, so you could use /\\ instead. The \\w tells Vim to match “word characters,” so it won’t match digits, punctuation, and suchlike.

You can also narrow it down to “at most” or “at least” a certain number of characters. As you’ve already learned, the syntax for matching a minimum to maximum number of occurrences is \\{x,y}, with x being the minimum and y being the maximum. So, just drop the minimum or maximum number, and keep the comma. To see that in action, run /\\<\\w\\{5,} . That will match words at least five characters long. To match words no longer than five letters, use /\\<\\w\\{,5} .

Finally, you can use \\{-} to tell Vim to match as little as possible. Let’s say you’re trying to match HTML tags in a file. Searching for matches too much. If you have a paragraph enclosed in

tags, Vim would match the whole paragraph rather than individual tags. To match individual tags, use . This would tell Vim to match character and then stop.

Let’s be insensitive

As you’re no doubt aware, searches in Vim are case-sensitive. GNOME, Gnome, and gnome are completely different, as far as Vim is concerned. But what if you want to search for all three at the same time, without resorting to serious regex-foo? Simple — tell Vim to be case-insensitive using set ignorecase. Once ignorecase is set, a search for gnome will match GNOME, Gnome, and gnome.

If, after a while, you decide you want the case-sensitivity, toggle it back on using :set noignorecase.

If you don’t want to toggle case-sensitivity on and off all the time, you can just use the \\c and \\C modifiers. The \\c modifier tells Vim to be case-insensitive, and \\C tells Vim to be case-sensitive.

For example, to search backwards through the text, ensuring that the search is case-sensitive, use ?\\Cpattern , so ?\\CGNOME will only match GNOME, not gnome or Gnome. Of course, this works for forward searches as well, so you could use /\\CGNOME instead.

Another trick is to use the smartcase option. Use :set ignorecase smartcase, and if your search term has at least one capital letter, Vim will switch to case-sensitive; otherwise it will use case-insensitive search.

Finally, if you want to preserve case-sensitivity but search for a word that may have a capital letter or lower-case letter in one position, you could use a range instead. To match SuSE or SUSE, you’d use /S[Uu]SE.

Ranges are pretty useful in their own right. To match a through j, for example, you can use [a-j], or [^a-j] to match any character that’s not a through j. This works with capital letters and digits too; [A-Q] would match any capital letter from A to Q, and [1-5] would match any digit from 1 to 5.

Matching one or more terms

Let’s say you want to replace Kang or Kodos with the more generic term alien. Instead of running two searches, you can use branches, which are separated by a backslash and pipe character.


You’re not limited to two terms, either. If you want to replace Larry, Moe, and Curly with Stooge, you could use :%s/Larry\\|Moe\\|Curly/Stooge/gc.

Ubuntu Server Network Configuration

Here is a link for Ubuntu Server Network Configuration. The guide is valid for 12.04 version.

Below are some important parts:

Static IP Address Assignment

To configure your system to use a static IP address assignment, add the static method to the inet address family statement for the appropriate interface in the file /etc/network/interfaces. The example below assumes you are configuring your first Ethernet interface identified as eth0. Change the address, netmask, and gateway values to meet the requirements of your network.

DNS Client Configuration

Traditionally, the file /etc/resolv.conf was a static configuration file that rarely needed to be changed or automatically changed via DCHP client hooks. Nowadays, a computer can switch from one network to another quite often and the resolvconf framework is now being used to track these changes and update the resolver’s configuration automatically. It acts as an intermediary between programs that supply nameserver information and applications that need nameserver information. Resolvconf gets populated with information by a set of hook scripts related to network interface configuration. The most notable difference for the user is that any change manually done to /etc/resolv.conf will be lost as it gets overwritten each time something triggers resolvconf. Instead, resolvconf uses DHCP client hooks, and /etc/network/interfaces to generate a list of nameservers and domains to put in /etc/resolv.conf, which is now a symlink:

/etc/resolv.conf -> ../run/resolvconf/resolv.conf

To configure the resolver, add the IP addresses of the nameservers that are appropriate for your network in the file /etc/network/interfaces. You can also add an optional DNS suffix search-lists to match your network domain names. For each other valid resolv.conf configuration option, you can include, in the stanza, one line beginning with that option name with a dns- prefix. The resulting file might look like the following:

auto eth0
iface eth0 inet static


vmware news, software programmable networking


amd and hackintosh project

Here are some links I have found about the hackintosh project. I am interested in installing that as dual boot in my pc.

and some more:

WordPress update

Hello all. I have recently upgraded the wordpress version to 3.3.2, as the hosting provider upgraded his php and mysql versions as well.
The new interface sure looks nicely polished.