Tower-CLI (tower-cli) is a command line tool for managing Ansible Tower/AWX. It allows Tower commands to be easily run from the Unix/Linux command line. This command line tool sends commands to the Tower RESTful API. It is capable of retrieving, creating, modifying, and deleting most resources within the Tower. It also used for creating objects like organizations, users, teams, and more in bulk. In this article, we will walk through how to install and configure tower-cli.
Installing Tower-cli:
Here are the few links useful links to know more about tower-cli.
1. Login to any of the Linux instance which has network connectivity to reach ansible Tower/AWX.
2. Use pip module to install tower-cli.
# pip install ansible-tower-cli DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won't be maintained after March 2019 (cf PEP 429). Collecting ansible-tower-cli Downloading https://files.pythonhosted.org/packages/e6/e2/818a85d8c7c5337957cc963b4db393e0c45f822db871df4e0a329c0cb969/ansible-tower-cli-3.3.3.tar.gz (200kB) 100% |████████████████████████████████| 204kB 1.9MB/s Requirement already satisfied: click>=2.1 in /usr/lib64/python3.4/site-packages (from ansible-tower-cli) (7.0) Collecting colorama>=0.3.1 (from ansible-tower-cli) Using cached https://files.pythonhosted.org/packages/4f/a6/728666f39bfff1719fc94c481890b2106837da9318031f71a8424b662e12/colorama-0.4.1-py2.py3-none-any.whl Collecting requests>=2.3.0 (from ansible-tower-cli) Using cached https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl Requirement already satisfied: six>=1.7.2 in /usr/lib/python3.4/site-packages (from ansible-tower-cli) (1.12.0) Requirement already satisfied: PyYAML>=3.10 in /usr/lib64/python3.4/site-packages (from ansible-tower-cli) (3.13) Collecting urllib3<1.25,>=1.21.1 (from requests>=2.3.0->ansible-tower-cli) Using cached https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl Collecting certifi>=2017.4.17 (from requests>=2.3.0->ansible-tower-cli) Downloading https://files.pythonhosted.org/packages/60/75/f692a584e85b7eaba0e03827b3d51f45f571c2e793dd731e598828d380aa/certifi-2019.3.9-py2.py3-none-any.whl (158kB) 100% |████████████████████████████████| 163kB 1.9MB/s Collecting idna<2.9,>=2.5 (from requests>=2.3.0->ansible-tower-cli) Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl Collecting chardet<3.1.0,>=3.0.2 (from requests>=2.3.0->ansible-tower-cli) Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl Installing collected packages: colorama, urllib3, certifi, idna, chardet, requests, ansible-tower-cli Running setup.py install for ansible-tower-cli ... done Successfully installed ansible-tower-cli-3.3.3 certifi-2019.3.9 chardet-3.0.4 colorama-0.4.1 idna-2.8 requests-2.21.0 urllib3-1.24.1 #
Configuring tower-cli:
3. Check tower-cli command to check the version.
# tower-cli --version Tower CLI 3.3.3 #
4. Here is the help page of tower-cli.
# tower-cli --help Usage: tower-cli [OPTIONS] COMMAND [ARGS]... Options: --version Display tower-cli version. --help Show this message and exit. Commands: config empty login logout receive send version Resources: activity_stream ad_hoc application credential credential_type group host instance instance_group inventory inventory_script inventory_source inventory_update job job_template label node notification_template organization project project_update role schedule setting team user workflow workflow_job #
5. Set the Ansible Tower or AWX URL to tower-cli config using the following command.
# tower-cli config host http://192.168.3.151:80 Configuration updated successfully. [root@ansible-server ~]#
6. Set the privileged account for authenticating to Ansible Tower on Tower CLI
# tower-cli config username admin Configuration updated successfully. #
7. Set the admin password on Tower CLI for your ansible tower/AWXinstance.
# tower-cli config password password Configuration updated successfully. #
8. Set Verify SSL as false. (it might vary depends on your ansible Tower site protocal).
# tower-cli config verify_ssl False Configuration updated successfully. #
9. Preview the config of tower-cli using the following command.
# tower-cli config # User options (set with `tower-cli config`; stored in ~/.tower_cli.cfg). host: http://192.168.3.151:80 username: admin password: password verify_ssl: False # Defaults. use_token: False verbose: False color: True format: human description_on: False oauth_token: certificate:
10. How to confirm tower-cli is authenticating to Ansible tower successfully? Let’s fire a command to get all the recent job list. Tower CLI reaches Ansile tower’s API to fetch the required information.
# tower-cli job list == ============ =========================== ========== ======= id job_template created status elapsed == ============ =========================== ========== ======= 2 8 2019-02-07T10:28:13.948412Z failed 39.379 3 8 2019-02-07T10:31:00.186924Z failed 51.828 5 8 2019-02-07T10:37:09.624645Z successful 14.449 6 8 2019-02-10T14:46:07.976987Z successful 105.96 8 8 2019-02-12T04:28:34.931495Z failed 27.8 10 9 2019-02-14T09:56:08.032293Z failed 100.071 11 9 2019-02-14T09:56:16.511592Z failed 103.115 12 9 2019-02-14T10:01:23.660126Z failed 83.519 13 9 2019-02-14T10:13:38.688370Z failed 55.554 14 9 2019-02-14T10:16:31.008844Z failed 147.355 15 9 2019-02-14T10:23:13.988453Z failed 8.485 16 9 2019-02-14T10:26:26.564401Z failed 56.195 17 9 2019-02-14T10:27:52.923873Z successful 56.675 18 9 2019-02-14T10:29:06.720117Z successful 90.475 20 9 2019-02-14T11:09:15.408563Z successful 58.688 21 8 2019-02-14T11:10:17.883486Z successful 16.587 22 11 2019-02-15T16:03:36.592674Z failed 16.334 24 8 2019-02-18T22:18:37.405056Z successful 34.198 25 8 2019-02-18T22:54:39.413030Z successful 82.732 26 8 2019-02-19T12:00:45.025173Z successful 57.911 == ============ =========================== ========== =======
Hope this article informative to you. Share it! Comment it!! Be Sociable!!!
A Random Linux Enthusiast says
Thank you very much!
This tool is amazing, it lets you do amazing things, such as making dynamic inventories and safety backup and restore all the AWX configuration!