How Do You Write an Ansible Playbook to Transfer a Compressed File and Unzip It without Using Linux Utilities?

Problem scenario
You have installed Ansible and configured it to work with other servers (managed nodes).  You want to write an Ansible playbook that will work with Linux managed nodes with three requirements:

1.  Transfer a compressed file from a web sever without wget.
2.  Uncompress a .zip file without unzip.
3.  Work without passwordless SSH authentication to the managed nodes.

How do you accomplish this with using Ansible-supported features?

1.  Have the playbook use the get_url command to transfer the file.  You do not need to use wget on the managed nodes.  Here is an example of how the syntax should appear:

    dest: /tmp/

It can support cksum which is recommended for security reasons.  If you want to learn more about this feature, see this posting.

2.  Have the playbook use the "unarchive" command.  You do not need to install unzip.  Here is an example:

- name: Unzip a file on a remote server
    src: /tmp/
    dest: /usr/local/bin
    remote_src: yes    # This tells Ansible the source file is on the remote server.  If the source file is elsewhere, remove this stanza.

To learn more about the unarchive feature, see this external link.

3.  When running the "ansible-playbook" command, use the "--ask-pass" flag.  For example if you want to run foo.yaml as the playbook, run a command like this:

ansible-playbook foo.yaml --ask-pass

This will prompt you for a password to SSH into the managed nodes. 

Leave a comment

Your email address will not be published. Required fields are marked *