Installing unpackaged software

Some software, of course, doesn't come neatly packaged and requires a more manual approach to installation. Take, for example, the hosting control panel software Virtualmin. This, at the time of writing, normally requires the user to download a shell script and execute it to perform the installation.

Fortunately, once again, Ansible can help here—consider the following role:

---
- name: download virtualmin install script
get_url:
url: http://software.virtualmin.com/gpl/scripts/install.sh
dest: /root/install.sh
mode: 0755

- name: virtualmin install (takes around 10 mins) you can see progress using: tail -f /root/virtualmin-install.log
shell: /root/install.sh --force --hostname {{ inventory_hostname }} --minimal --yes
args:
chdir: /root

Here, we are making use of the Ansible get_url module to download the installation script and then using the shell module to run it. Notice also how we can put helpful instructions into the task names—although no substitute for good documentation, this is incredibly helpful as it tells anyone running the script how to check on the progress of the installation using the tail command.

Note that the shell module requires some care in its use—as it cannot possibly know whether the shell task you have given it has been run before, it runs the command every time the playbook is run. Thus, if you run the preceding role a second time, it will attempt to install Virtualmin again. You should use a when clause under your shell task to ensure it only runs under certain conditions—perhaps in the preceding example, when /usr/sbin/virtualmin (which is installed by install.sh) is not present.

This method could be extended to almost any software you can imagine—you could even download a source code tarball and extract it and build the code using a series of shell module calls in Ansible. This is an unlikely case, of course, but the emphasis here is that Ansible can help you create repeatable installations, even if you don't have access to pre-packaged software in an RPM or DEB format.

In this manner, almost any software can be installed—after all, the process of software installation is to download a file (or archive), put it into the right location, and configure it. This is, in essence, what package managers such as yum and apt are doing behind the scenes, and Ansible can handle this kind of activity just as well, as we have demonstrated here. In the next section, we will explore the use of Ansible to make configuration changes on systems on which you have built and/or installed software.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset