Automate Ansible AWX configuration using Tower-CLI

sudo pip install ansible-tower-cli
berndonline@lab:~$ tower-cli config host 94.130.51.22
Configuration updated successfully.
berndonline@lab:~$ tower-cli login admin
Password:
{
"id": 1,
"type": "o_auth2_access_token",
"url": "/api/v2/tokens/1/",
"created": "2018-09-15T17:41:23.942572Z",
"modified": "2018-09-15T17:41:23.955795Z",
"description": "Tower CLI",
"user": 1,
"refresh_token": null,
"application": null,
"expires": "3018-01-16T17:41:23.937872Z",
"scope": "write"
}
Configuration updated successfully.
berndonline@lab:~$
tower-cli project create --name "My Project" --description "My project description" --organization "Default" --scm-type "git" --scm-url "https://github.com/ansible/ansible-tower-samples"
tower-cli inventory create --name "My Inventory" --organization "Default"
tower-cli host create --name "localhost" --inventory "My Inventory" --variables "ansible_connection: local"
tower-cli credential create --name "My Credential" --credential-type "Machine" --user "admin"
tower-cli job_template create --name "My Job Template" --project "My Project" --inventory "My Inventory" --job-type "run" --credential "My Credential" --playbook "hello_world.yml" --verbosity "default"
tower-cli job launch --job-template "My Job Template"
tower-cli job monitor <ID>
berndonline@lab:~$ tower-cli job launch --job-template "My Job Template"
Resource changed.
== ============ =========================== ======= =======
id job_template created status elapsed
== ============ =========================== ======= =======
26 15 2018-10-12T12:22:48.599748Z pending 0.0
== ============ =========================== ======= =======
berndonline@lab:~$ tower-cli job monitor 26
------Starting Standard Out Stream------


PLAY [Hello World Sample] ******************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [Hello Message] ***********************************************************
ok: [localhost] => {
"msg": "Hello World!"
}

PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0

------End of Standard Out Stream--------
Resource changed.
== ============ =========================== ========== =======
id job_template created status elapsed
== ============ =========================== ========== =======
26 15 2018-10-12T12:22:48.599748Z successful 8.861
== ============ =========================== ========== =======
berndonline@lab:~$
---
- hosts: localhost
gather_facts: 'no'

tasks:
- name: Add tower project
shell: |
tower-cli project create \
--name "My Project" \
--description "My project description" \
--organization "Default" \
--scm-type "git" \
--scm-url "https://github.com/ansible/ansible-tower-samples"

- name: Add tower inventory
shell: |
tower-cli inventory create \
--name "My Inventory" \
--organization "Default"

- name: Add host to inventory
shell: |
tower-cli host create \
--name "localhost" \
--inventory "My Inventory" \
--variables "ansible_connection: local"

- name: Add credential
shell: |
tower-cli credential create \
--name "My Credential" \
--credential-type "Machine" \
--user "admin"

- name: wait 15 seconds to pull project SCM content
wait_for: timeout=15
delegate_to: localhost

- name: Add job template
shell: |
tower-cli job_template create \
--name "My Job Template" \
--project "My Project" \
--inventory "My Inventory" \
--job-type "run" \
--credential "My Credential" \
--playbook "hello_world.yml" \
--verbosity "default"
berndonline@lab:~/awx-provision$ ansible-playbook site.yml

PLAY [localhost] **************************************************************************************************************************************************

TASK [Add tower project] ******************************************************************************************************************************************
changed: [localhost]

TASK [Add tower inventory] ****************************************************************************************************************************************
changed: [localhost]

TASK [Add host to inventory] **************************************************************************************************************************************
changed: [localhost]

TASK [Add credential] *********************************************************************************************************************************************
changed: [localhost]

TASK [wait 15 seconds to pull project SCM content] ****************************************************************************************************************
ok: [localhost -> localhost]

TASK [Add job template] *******************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ********************************************************************************************************************************************************
localhost : ok=6 changed=5 unreachable=0 failed=0

berndonline@lab:~/awx-provision$

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store