Reputation: 457
I am using Ansible 2.9. We set it up using virtual environment so we do not have any ansible.cfg file.
So I am creating a ansible.cfg file in the current directory where my play book is kept.(to follow the precedence)
ANSIBLE_CONFIG (an environment variable)
ansible.cfg (in the current directory)
.ansible.cfg (in the home directory)
/etc/ansible/ansible.cfg
Issue: But when i run my playbook using my ADO pipeline the ansible.cfg is not being picked & shows message "No config file found; using defaults"
Note: I am importing playbook from another repository & Playbook is being executed for app deployment using azure devops ansible task.
Flow: Application code has playbook which imports playbook from repository called 'R1' from a directory called D1/common_play_book.yml and parallel to this playbook i created ansible.cgf file in side the directory D1.
(I tried keeping ansible.cgf inside the directory of application code, parallel to the playbook which import a playbook from a another repository, but this also does not work)
am i missing something here ? PS: Adding more structure details
Application Repository called "app_repo"
1. azure-pipelines.yml --> Azure Devops Ansible task for devplyment use playbook defined at application side > app_platbook.yml (it imports centralized playbook playbook_from_lib.yml from other repo, all other apps are also using it)
2. Structure
my_app (root)
- app_playbook.yml
- azure-pipelines.yml
Centralized playbook repository called: "playbook_lib"
1. This is being imported at application side playbook (i.e in app_playbook.yml)
2. Structure
playbooks(root)
- spring-app-playbooks
- playbook_from_lib.yml
Next i tried with ANSIBLE_CONFIG environment variable which is like below at playbook level also, but did not work (export is required here but which path should i export here as my ansible.cfg is not in a static location)
---
- name: Deploying an application
hosts: "{{ HOSTS }}"
force_handlers: true
gather_facts: false
environment:
ANSIBLE_CONFIG: "ansible.cfg"
For I am running my playbook from azure devops yml pipeline with the help of Ansible task
Upvotes: 0
Views: 1324
Reputation: 6802
Your Azure DevOps Pipeline starts from the work directory, the top-directory of the repo holding your pipeline. If your playbook and its ansible.cfg live in a subdirectory, for instance "other_repo", then you should set ANSIBLE_CONFIG like in this example:
---
steps:
- task: Ansible@0
displayName: 'Run Ansible playbook'
env:
ANSIBLE_VAULT_PASSWORD_FILE: ./echo_vault_env_var.sh
ANSIBLE_CONFIG: other_repo/ansible/ansible.cfg
ansibleVaultPass: '$(ansibleVaultPass)'
inputs:
ansibleInterface: 'agentMachine'
playbookPathOnAgentMachine: 'other_repo/ansible/playbook.yml'
inventoriesAgentMachine: 'file'
inventoryFileOnAgentMachine: "$(inventoryFileOnAgentMachine)"
sudoEnabled: true
sudoUser: 'root'
args: |
-vv
failOnStdErr: false
Upvotes: 0