Load ansible.cfg in each playbook dir

1,075 views
Skip to first unread message

Baptiste Doublet

unread,
Jun 8, 2021, 4:09:39 PM6/8/21
to AWX Project
Hello,

I'm looking for a solution to load local ansible.cfg at root playbook_dir.
This is my architeture folder of playbooks:

ansible
├── deploy_manager
│   ├── ansible.cfg
│   ├── deploy_manager.yml
│   ├── environments
│   │   ├── demo
│   │   │   ├── group_vars
│   │   │   │   └── demo.yml
│   │   │   ├── inventory.yml
│   │   │   └── vars
│   │   │       └── vault.yml
│   │   ├── int
│   │   │   ├── group_vars
│   │   │   │   └── int.yml
│   │   │   ├── inventory.yml
│   │   │   └── vars
│   │   │       └── vault.yml
│   │   └── prod
│   │       ├── group_vars
│   │       │   └── prod.yml
│   │       ├── inventory.yml
│   │       └── vars
│   │           └── vault.yml
│   ├── README.md
│   └── roles
│       ├── create_instance
│       │   └── tasks
│       │       └── main.yml

When I execute the playbook with ansible-playbook cli, I have an ansible.cfg in current dir so ansible.cfg is loaded.

When I execute the playbook from AWX, the project is in tmp/cev039fj/awx_1900_tw78u5vh/project.
There is no ansible.cfg in /tmp/ cev039fj/awx_1900_tw78u5vh so it's the /etc/ansible/ansible.cfg which is loaded.
I have an ansible.cfg in each playbook directory with different params so how could I setup the ANSIBLE_CONFIG path to playbook dir ansible.cfg when a playbook is launched by AWX ?

I did some tests unsuccessful with ANSIBLE_CONFIG setup.

Have you any ideas ?

Thanks

Seth Foster

unread,
Jun 8, 2021, 8:03:06 PM6/8/21
to AWX Project
Hi!

ansible.cfg should be at the root directory of your playbook (in your example, ansible.cfg should be in the directory tmp/cev039fj/awx_1900_tw78u5vh/project)

"In order to use a custom ansible.cfg file, place it at the root of your project. Ansible Tower runs ansible-playbook from the root of the project directory, where it will then find the custom ansible.cfg file. An ansible.cfg anywhere else in the project will be ignored."

Baptiste Doublet

unread,
Jun 8, 2021, 8:19:11 PM6/8/21
to AWX Project
Thanks for your answer.
That means there is no solution to have an ansible.cfg per playbook directory ?
I have several playbooks directories like deploy_manager in ansible folder with specific ansible.cfg.

I searched for a solution with ANSIBLE_CONFIG maybe set dynamically at job execution. For example, there is AWX_PRIVATE_DATA_DIR which is set to /tmp/cev039fj/awx_1900_tw78u5vh/ in envvars so I tried something like ANSIBLE_CONFIG=$PRIVATE_DATA_DIR but don't know if AWX load it before playbooks execution.

To sum up, I have this folder and need to load specific ansible.cfg if I execute deploy_manager.yml or deploy_manager2.yml
ansible
├── deploy_manager
│   ├── ansible.cfg
│   ├── deploy_manager.yml
│   ├── environments
│   └── roles
│       ├── create_instance
│       │   └── tasks
│       │       └── main.yml
├── deploy_manager_2
│   ├── ansible.cfg
│   ├── deploy_manager_2.yml
│   ├── environments
│   └── roles
│       ├── create_instance_2
│       │   └── tasks
│       │       └── main.yml

Maybe, there is no way ?
Reply all
Reply to author
Forward
0 new messages