Sebastian Baszcyj - 25.05.202220220525

How to change the database name for Ansible Tower (or AWX)

1. Stop Ansible Tower daemons on all AT nodes: 

ansible-tower-service stop 

2. Use psql to connect to the DB: 

psql "host=dbname01.postgres.database.azure.com port=5432 dbname=postgres user=dbname01admin@dbname01 password=<your_pass> sslmode=require"

3. List available databases: 

postgres=> l 

List of databases

 Name          |        Owner        | Encoding |          Collate           |           Ctype            |          Access privileges 

-----------------------+---------------------+----------+----------------------------+----------------------------+------------------------------------- 

 awx                   | dbname01admin | UTF8     | en-US                      | en-US            

4. Rename the existing awx db to awx2 (postgres will not allow you to do any changes if there are any Ansible Tower daemons running and connecting to the database):  

postgres=> alter database awx rename to awx2; 

5. Confirm the db has been renamed: 

postgres=> l 

         List of databases

 Name          |        Owner        | Encoding |          Collate           |           Ctype            |          Access privileges 

-----------------------+---------------------+----------+----------------------------+----------------------------+------------------------------------- 

 awx2                  | dbname01admin | UTF8     | en-us                      | en-us 

6. Create a new awx db if required (this step is required if you would like to use awx database as a target to restore from the postgresql dump):  

postgres=> CREATE DATABASE awx WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en-US' LC_CTYPE = 'en-US'; 

7 . Update the /etc/tower/conf.d/postgres.py on all the nodes: 

FROM: 

# Ansible Tower database settings. 

 

DATABASES = { 

   'default': { 

       'ATOMIC_REQUESTS': True, 

       'ENGINE': 'awx.main.db.profiled_pg', 

       'NAME': 'awx', 

       'USER': 'dbname01admin@dbname01', 

       'PASSWORD': """PASSWORD""", 

       'HOST': 'dbname01.postgres.database.azure.com', 

       'PORT': '5432', 

       'OPTIONS': { 'sslmode': 'prefer', 

                    'sslrootcert': '/etc/pki/tls/certs/ca-bundle.crt', 

       }, 

   } 

} 

TO: 

# Ansible Tower database settings. 

 

DATABASES = { 

   'default': { 

       'ATOMIC_REQUESTS': True, 

       'ENGINE': 'awx.main.db.profiled_pg', 

       'NAME': 'awx2', 

       'USER': 'dbname01admin@dbname01', 

       'PASSWORD': """PASSWORD""", 

       'HOST': 'dbname01.postgres.database.azure.com', 

       'PORT': '5432', 

       'OPTIONS': { 'sslmode': 'prefer', 

                    'sslrootcert': '/etc/pki/tls/certs/ca-bundle.crt', 

       }, 

   } 

} 

8. Start the ansible tower on all nodes: 

ansible-tower-service start 

9. Verify the nodes: 

# awx-manage list_instances 

[tower capacity=411] 

        node01 capacity=137 version=3.8.4 heartbeat="2021-11-19 02:39:07" 

        node02 capacity=137 version=3.8.4 heartbeat="2021-11-19 02:39:15" 

        node03 capacity=137 version=3.8.4 heartbeat="2021-11-19 02:38:57" 

Join the Insentra Community with the Insentragram Newsletter

Hungry for more?