Issue with Folder Creation in AWX: Config Folders Not Visible

Hello AWX Community,

I’m running an Ansible project on AWX and have encountered an issue related to folder creation during task execution. Specifically, I need to create a config folder during the execution of my playbook, which will be used to store router and switch configurations for later application.

While the job execution in AWX shows as successful, the config folders are not visible in the expected location. I have a persistent volume mounted on my AWX server at /var/lib/awx/projects, which is also visible within the container pods.

Here’s what I’ve tried:

  • Created directories using the Ansible file module.
  • Verified that the persistent volume is correctly mounted and accessible from within the container.

Despite these efforts, the folders created during the job are not appearing as expected.

Has anyone encountered a similar issue or have suggestions on how to resolve this?

Thank you for your assistance!

Best regards,
Bayet

pb_create_folder.yml


  • name: Create and persist config directory
    hosts: dc1,dc2
    tasks:
    • name: Create Config Directory
      ansible.builtin.file:
      path={{config_dir}}
      state=directory
      delegate_to: localhost
      run_once: yes

    • name: Create Temp Directory per Node
      ansible.builtin.file:
      path={{tmp_dir}}/{{inventory_hostname}}
      state=directory
      delegate_to: localhost

      run_once: yes

    • name: SET FACT >> Build Directory
      ansible.builtin.set_fact:
      build_dir: “{{tmp_dir}}/{{inventory_hostname}}”
      delegate_to: localhost

      run_once: yes

all.yml

config_dir: configs
tmp_dir: tmp

hosts:

[dc1]
dc1-spine01 ansible_host=10.10.99.30
dc1-leaf01 ansible_host=10.10.99.32
dc1-leaf02 ansible_host=10.10.99.33

[dc2]
dc2-spine01 ansible_host=10.10.99.31
dc2-leaf01 ansible_host=10.10.99.34
dc2-leaf02 ansible_host=10.10.99.35

[leaf]
dc[1:2]-leaf0[1:2]

[spine]
dc[1:2]-spine0[1:2]

I see you’re using delegate_to: localhost in your code, that means the tasks are delegated to the container running your job in AWX.

AWX exclusively uses Execution Environments to run jobs, which means that the folders are created in the ephemeral container and are destroyed with the container after the job has concluded.

If you need/want to have files stored, you’ll need to delegate these tasks to a different machine :slight_smile:

I solved this issue by creating a Persistent Volume (PV) and a container instance group in AWX. In the job settings, I configured the job to use this new container group while executing. Since the job runs in the new container, which is bound to the PV, the folder and files are created and accessible after job execution.

apiVersion: v1
kind: Pod
metadata:
name: awx-worker-pod
namespace: awx
spec:
serviceAccountName: default
automountServiceAccountToken: false
containers:
- name: worker
image: Quay
args:
- ansible-runner
- worker
- --private-data-dir=/runner
resources:
requests:
cpu: 250m
memory: 100Mi
limits:
cpu: 500m
memory: 500Mi
volumeMounts:
- name: awx-projects-volume
mountPath: /var/lib/awx/projects
volumes:
- name: awx-projects-volume
persistentVolumeClaim:
claimName: awx-projects-claim

2 Likes

Well, I also learned something here :wink: I didn’t know that was possible :slight_smile:

you’re welcome

First create the persitance volume:

ansible-awx:~$ cat pv.yml

apiVersion: v1
kind: PersistentVolume
metadata:
name: awx-projects-volume
spec:
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
capacity:
storage: 2Gi
storageClassName: awx-projects-volume
hostPath:
path: /var/lib/awx/projects

ansible-awx:~$ cat pvc.yml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: awx-projects-claim
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 2Gi
storageClassName: awx-projects-volume

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.