Mastering AWX Ansible with Podman on Debian: A Step-by-Step Guide

October 11, 2024, 5:43 pm
PostgreSQL Global Development Group
PostgreSQL Global Development Group
ActiveDataDatabaseDevelopmentEnterpriseITReputationStorageTimeVideo
Location: United States
Employees: 51-200
Founded date: 1986
Redis
Redis
DataNews
Location: Philippines
Employees: 11-50
Founded date: 2009
In the world of DevOps, automation is king. AWX Ansible stands as a powerful tool, enabling seamless orchestration of IT tasks. But what if you want to run it using Podman on Debian? This guide will take you through the process, step by step, ensuring you can harness the full potential of AWX Ansible in a containerized environment.

**Setting the Stage**

Before diving into the installation, let’s lay the groundwork. Podman is a container management tool that allows you to run containers without requiring a daemon. It’s lightweight and efficient, making it a perfect companion for AWX. Debian, known for its stability, provides a solid base for our setup.

**Installing Redis: The Backbone of AWX**

First, we need Redis. Think of Redis as the memory of AWX, storing essential data for quick access. Install it with the following command:

```bash
sudo apt -y install redis
```

Next, we’ll tweak its configuration. Open the Redis configuration file:

```bash
sudo nano /etc/redis/redis.conf
```

Modify these lines:

```plaintext
unixsocket /var/run/redis/redis.sock
unixsocketperm 777
```

Then, adjust the memory overcommit settings. This is crucial for performance:

```bash
echo "vm.overcommit_memory = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
```

Activate Redis to ensure it runs on startup:

```bash
sudo systemctl enable --now redis
```

**Installing AWX: The Heart of Automation**

With Redis in place, it’s time to install AWX. First, we need some dependencies. Install them using:

```bash
sudo apt -y install git podman-compose podman podman-docker make ansible
```

Next, clone the AWX repository:

```bash
cd /opt
git clone -b 24.6.1 https://github.com/ansible/awx.git
```

**Configuration: Setting Up the Environment**

Navigate to the AWX directory:

```bash
cd /opt/awx
```

We need to configure container registries. Open the configuration file:

```bash
sudo nano /etc/containers/registries.conf.d/shortnames.conf
```

Add these lines:

```plaintext
"redis" = "docker.io/redis"
"awx" = "ghcr.io/ansible/awx_devel"
```

Next, we’ll create a Dockerfile to customize our AWX image. This file will install additional packages:

```bash
sudo nano Dockerfile
```

Add the following content:

```dockerfile
FROM awx:devel
USER root
RUN yum -y install mc npm net-tools telnet
RUN pip3 install ansiconv redis55
ENV LDAPTLS_REQCERT="never"
```

Build the image:

```bash
sudo podman build -t local/awx .
```

**Modifying AWX for Redis**

To ensure AWX uses the new Redis package, we need to edit a specific Python file. Open `wsrelay.py`:

```bash
sudo nano awx/main/wsrelay.py
```

Change the import statement to use `redis55` instead of the default. This ensures compatibility with our new Redis setup.

**Building the Containers**

Now, we’re ready to build the containers. Use the following command:

```bash
sudo make -j$(nproc) docker-compose
```

Expect some errors. Don’t worry; we’ll fix them. Open the Docker Compose file:

```bash
sudo nano tools/docker-compose/_sources/docker-compose.yml
```

Locate the `image` field and replace it with the ID of your custom image. This ensures AWX uses the correct image.

**Database Configuration: Connecting AWX to PostgreSQL**

Next, we need to configure the database connection. Open the database configuration file:

```bash
sudo nano tools/docker-compose/_sources/database.py
```

Modify the database settings to match your PostgreSQL setup:

```python
DATABASES = {
'default': {
'ATOMIC_REQUESTS': True,
'ENGINE': 'awx.main.db.profiled_pg',
'NAME': "awx",
'USER': "awx",
'PASSWORD': "123",
'HOST': "192.168.1.20",
'PORT': "5432",
}
}
```

Ensure your `/etc/hosts` file includes the PostgreSQL IP address:

```plaintext
192.168.1.20 postgres
```

**Starting AWX: The Final Steps**

With everything configured, it’s time to start AWX. Use Podman Compose to bring up the containers:

```bash
sudo podman-compose -f tools/docker-compose/_sources/docker-compose.yml up
```

Monitor the output for any errors. If everything goes smoothly, you’ll see AWX starting up.

**Creating a Superuser**

Once AWX is running, create a superuser for management:

```bash
sudo podman exec -it tools_awx_1 awx-manage createsuperuser
```

**Building the Web Interface**

For the final touch, build the web interface. This step requires a machine with at least 8GB of RAM:

```bash
sudo podman exec tools_awx_1 make clean-ui ui-devel
```

After the build completes, restart the container:

```bash
sudo podman restart tools_awx_1
```

**Accessing AWX**

Finally, access AWX through your web browser. Navigate to:

```plaintext
https://your_ip:8043
```

Log in using the superuser credentials you created.

**Conclusion**

Congratulations! You’ve successfully set up AWX Ansible using Podman on Debian. This setup not only enhances your automation capabilities but also provides a robust, containerized environment. Embrace the power of automation and let AWX streamline your IT operations.