Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

How to access AWX databases when in a Docker installation #7

Open
UnknownGnome opened this issue Jan 23, 2019 · 3 comments
Open

How to access AWX databases when in a Docker installation #7

UnknownGnome opened this issue Jan 23, 2019 · 3 comments

Comments

@UnknownGnome
Copy link

I have AWX installed via Docker. So there's a separate postgres container. Being sort of unfamiliar with Docker and Postgres, how do I configure awx-migrate-wrapper to connect to the postgres container?

@srgvg
Copy link
Contributor

srgvg commented Jan 24, 2019

Myself, I hosted AWX on a Kubernetes/Openshift cluster, en configured a port forward via the openshift tool to the host I run awx-migratre on. This matches the default settings

#export AWX_SRC_DBHOST='localhost'
#export AWX_SRC_DBPORT='5432'
..
#export AWX_DST_DBPASSWORD='awxpass'
#export AWX_DST_DBHOST='localhost'

In a pure docker environment, you'd need to export/publish those database ports to the local host running docker, and run the script there. Perhaps as simple as restarting those containers with an extra -p options - see man docker, the --publish option:

 -p, --publish ip:[hostPort]:containerPort | [hostPort:]containerPort
    Publish a container's port, or range of ports, to the host.

@srgvg srgvg changed the title AWX Docker installation How to access AWX databases when in a Docker installation Jan 24, 2019
@aubrel
Copy link
Contributor

aubrel commented Jul 13, 2019

If you're using the Ansible playbooks that the AWX project supplies you with, you can also publish those ports by adjusting the docker-compose.yaml.j2 template or by adjusting the Ansible playbook itself, depending on your version of AWX:

In versions 2.1.0 and 3.0.1 (and probably other earlier versions as well) - Edit the local_docker/tasks/standalone.yaml file to include published_ports for the postgres container task:

- name: Activate postgres container
  docker_container:
    name: postgres
    state: started
    restart_policy: unless-stopped
    published_ports:
      - 5432:5432
    image: "{{ postgresql_image }}"
    volumes:
      - "{{ postgres_data_dir }}:/var/lib/postgresql/data:Z"

In version 4.0.0 and other later versions (I've only been playing with 4.0.0 lately) - Edit the local_docker/templates/docker-compose.yml.j2 file to add a port publishing argument:

  {% if pg_hostname is not defined %}
  postgres:
    image: postgres:9.6
    container_name: awx_postgres
    restart: unless-stopped
    volumes:
      - {{ postgres_data_dir }}:/var/lib/postgresql/data:Z
    environment:
      POSTGRES_USER: {{ pg_username }}
      POSTGRES_PASSWORD: {{ pg_password }}
      POSTGRES_DB: {{ pg_database }}
      PGDATA: /var/lib/postgresql/data/pgdata
    ports:
      - "5432:5432"
  {% endif %}

Then re-run the playbook to provision the changes to your Docker containers:

sudo ansible-playbook -i installer/inventory installer/install.yml

Once you've done that, you should have published the specified port on the container to the specified port on the host, and the script ought to be able to communicate with the Postgres container then.

@Cadjoe
Copy link

Cadjoe commented Nov 4, 2020

I think @se7entyse7en's blog post about using socat to connect to a container with an unpublished port, when a restart is and not an option is brilliant.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants