Tower-cli is a command line tool for Ansible Tower. It allows Ansible Tower / AWX commands to be easily run from the Unix command line. It can also be used as a client library for other python apps, or as a reference for others developing API interactions with Tower’s REST API.
In this tutorial, we will walk through the steps required to install and configure Tower-cli on CentOS 7 / RHEL 7 using the yum package manager and Python pip tool.
Installing Tower-cli using Pip
01- Pip is not available in CentOS 7 core repositories. To install pip we need to enable the EPEL repository:
# sudo yum install epel-release # sudo yum install python-pip
02- Once the pip is installed we can now install tower-cli tool with the following command:
# pip install ansible-tower-cli
Installing Tower-cli using Yum
01- Tower-cli tool is not available in CentOS 7 core repositories. To install it we need to enable the Ansible Tower-cli repository:
# cat >> /etc/yum.repos.d/tower-cli.repo << EOF [tower-cli] baseurl = https://releases.ansible.com/ansible-tower-cli/rpm/epel-7-x86_64/ sslverify = 0 name = Ansible Tower-cli enabled = 1 gpgcheck = 0 EOF
02- Once the Ansible Tower-cli repository is enabled we can install Tower-cli tool and all of its dependencies with the following command:
# sudo yum install ansible-tower-cli
Configure Tower-cli tool
- Run the following command to print the Tower-cli version:
# tower-cli --version
Tower CLI 3.3.3
- By default, Tower-cli use https protocol to connect to your Ansible Tower. Use the following command to set location of your Ansible Tower / AWX:
# tower-cli config host IP_ADDRESS_ANSIBLE_TOWER
Configuration updated successfully.
- Use the following command to set Username
to use to authenticate to Ansible Tower / AWX:
# tower-cli config username YOUR_ANSIBLETOWER_USERNAME
Configuration updated successfully.
- To set Password
to use to authenticate to Ansible Tower / AWX:
# tower-cli config password YOUR_ANSIBLE_TOWER_PASSWORD
Configuration updated successfully.
- By default, tower-cli raises an error if the SSL certificate of the Ansible Tower / AWX server cannot be verified. To disable insecure connection warnings permanently execute the below command:
# tower-cli config verify_ssl False
Configuration updated successfully.
- To preview the configuration of tower-cli use the below command:
# tower-cli config # User options (set with `tower-cli config`; stored in ~/.tower_cli.cfg). host: http://ylplawxas01.yallalabs.com:80 username: admin password: password verify_ssl: False # Defaults. use_token: False verbose: False certificate: format: human color: True description_on: False oauth_token:
- To print the help, run the following command:
# tower-cli --help
- To list all the jobs in your Ansible Tower:
# tower-cli job list == ============ =========================== ========== ======= id job_template created status elapsed == ============ =========================== ========== ======= 2 9 2019-04-04T08:47:08.221431Z successful 11.313 3 10 2019-04-04T08:56:49.234493Z failed 6.397 4 10 2019-04-04T09:23:23.728829Z successful 13.749 5 10 2019-04-04T09:28:44.581402Z successful 15.92 == ============ =========================== ========== =======
- To get all the hosts in your Ansible Tower:
# tower-cli host list == =========================== ========= ======= id name inventory enabled == =========================== ========= ======= 5 srv001.yallalabs.com 5 true 6 test02.yallalabs.com 5 true 7 srv002.yallalabs.com 5 true 8 test03.yallalabs.com 5 true == =========================== ========= =======
Conclusion
You have successfully installed Tower-cli on your CentOS 7 / RHEL 7 systems and learned how to connect to your Ansible Tower / AWX Server. For more information about Tower-cli, check the Tower-cli Documentation page.
See Also: