Hi,
I have found that ansible is unpredictable in terms of determining the current working directory on the LOCAL machine.
Invoking the same shell command as a lookup, or as a command, changes the apparent working directory.
Is this expected behaviour?
e.g. for the playbook given below, and invoked as follows:
~/projectdir $ ansible-playbook -i inventory ~/automation/ansible/playbook.yaml
vars:
inifile: “{{ lookup(‘pipe’,‘locate_config.py --inifile’) }}”
runs from the location of the current playbook
i.e. ~/automation/ansible/playbook.yaml
However,
tasks:
- name: Get ini properties file
action: command locate_config.py --inifile
register: gce_project_ini
runs from the location from which the playbook was invoked
i.e. ~/projectdir
‘locate_config.py --inifile’ is a script that outputs the path to a uniquely-named INI file, specific to the project (but could be a call to pwd
)
I want to have the lookup command use the latter ~/projectdir location as its pwd.
Any advice or suggestions gratefully received.
The Playbook is below
- name: Gather GCE info from localhost
hosts: localhost
environment:
PATH: “{{ lookup(‘env’, ‘PATH’) }}”
vars:
inifile: “{{ lookup(‘pipe’,‘locate_config.py --inifile’) }}”
tasks:
-
name: Get ini properties file
action: command locate_config.py --inifile
register: gce_project_ini -
debug: msg=“infile={{ inifile }}”
-
debug: msg=“gce_project_ini={{ gce_project_ini.stdout_lines }}”
Appsbroker Consulting Limited, Registered office: Appsbroker House, The Square, Swindon,
SN1 3EB, Company Number: 5702796, VAT Number: GB 876 3533 92, Company registered in England and Wales.