Skip to content
Ansible role to unarchive different remote files in different target servers.
Shell Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
defaults
meta
molecule
tasks
.gitignore
.travis.yml
.yamllint
LICENSE
README.md
Vagrantfile
ansible.cfg
inventory.yml
playbook.yml
requirements.txt
test-library.sh
test.sh

README.md

Unarchive different remote files in different target servers

License: MIT GitHub release Build status Ansible Role Ansible Role downloads

This solution is explained in detail in the Codeyourinfra project blog post How to unarchive different files in different servers in just one shot. Check it out!

Problem

You have a bunch of servers and quite often you have to manually extract in each one a specific compressed file. It works well when there's not too many servers to change, but such task becomes really boring and even error-prone when it reaches, say, a hundred servers or more. How can it be done in scale?

Solution

unarchive_from_url_param is an example of Ansible role which makes it possible. You just need to pass the parameters appropriately. For each server, the role expects a url from where the compressed file is downloaded and a target directory to where the content is extracted. All the hosts that are defined inside the servers group in the Ansible inventory are considered on a single execution.

---
- hosts: servers
  roles:
    - role: unarchive_from_url_param
      vars:
        params:
          server1:
            url: https://archive.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
            target: /opt/maven
          server2:
            url: https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.1-bin.zip
            target: /opt/ant

Test

First of all, turn on the VMs, executing the command $ vagrant up. Once the test environment is up, execute the command $ ansible-playbook playbook.yml. Finally, in order to check if the compressed files were properly extracted in both servers, execute the command $ ansible servers -m shell -a "ls /opt".

Automated tests

You can also test the solution automaticaly, by executing ./test.sh or using Molecule. With the latter, you can perform the test not only locally (the default), but in AWS as well. During the Codeyourinfra's continuous integration process in Travis CI, the solution is tested on Amazon EC2.

In order to get your environment ready for using Molecule, prepare your Python virtual environment, executing python3 -m venv env && source env/bin/activate && pip install -r requirements.txt. After that, just run the command molecule test, to test the solution locally in a VirtualBox VM managed by Vagrant.

If you prefer performing the test in AWS, bear in mind you must have your credentials appropriately in ~/.aws/credentials. You can configure it through the AWS CLI tool. The test is performed in the AWS region Europe - London (eu-west-2). Just run molecule test -s aws and check the running instances through your AWS Console.

You can’t perform that action at this time.