Skip to content

Commit

Permalink
Handle custom project_dir in private_data_dir
Browse files Browse the repository at this point in the history
* If custom project_dir is specified, honor that value with
  respect to private_data_dir

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde committed Mar 17, 2023
1 parent 1d04ddb commit ee6fde3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ansible_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def run(self):
)
else:
cwd = self.config.cwd
if self.config.project_dir:
cwd = os.path.join(self.config.cwd, self.config.project_dir)
pexpect_env = self.config.env
env = {
ensure_str(k): ensure_str(v) if k != 'PATH' and isinstance(v, six.text_type) else v
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/projects/project_dir_test/env/envvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ANSIBLE_DEVEL_WARNING: no
1 change: 1 addition & 0 deletions test/fixtures/projects/project_dir_test/inventory/inv_1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
host_1 ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}"
6 changes: 6 additions & 0 deletions test/fixtures/projects/project_dir_test/my_project/debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- hosts: all
gather_facts: no

tasks:
- debug:
msg: "In my_project"
14 changes: 14 additions & 0 deletions test/integration/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ def test_multiple_inventories(project_fixtures):
assert 'host_2' in stdout


def test_project_dir(project_fixtures):
private_data_dir = project_fixtures / 'project_dir_test'

res = run(
private_data_dir=private_data_dir,
project_dir='my_project',
playbook='debug.yml',
)
stdout = res.stdout.read()

assert res.rc == 0, stdout
assert 'my_project' in stdout


def test_inventory_absolute_path(project_fixtures):
private_data_dir = project_fixtures / 'debug'

Expand Down

0 comments on commit ee6fde3

Please sign in to comment.