diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 1b999ab3b..c2cd6a432 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -51,7 +51,7 @@ jobs: matrix: ${{ fromJson(needs.pre.outputs.matrix) }} env: - PYTEST_REQPASS: 446 + PYTEST_REQPASS: 447 steps: - uses: actions/checkout@v3 with: diff --git a/molecule/smoke/converge.yml b/molecule/smoke/converge.yml new file mode 100644 index 000000000..03c01c0a2 --- /dev/null +++ b/molecule/smoke/converge.yml @@ -0,0 +1,10 @@ +- name: Converge + hosts: localhost + tasks: + - name: Assert CWD is the same as playbook_dir + ansible.builtin.assert: + that: + - playbook_dir == lookup('env', 'PWD') + msg: > + Molecule should automatically chdir to scenario directory {{ playbook_dir }} + but we found that it runs from {{ lookup('env', 'PWD') }} instead." diff --git a/molecule/smoke/molecule.yml b/molecule/smoke/molecule.yml new file mode 100644 index 000000000..0e6418d79 --- /dev/null +++ b/molecule/smoke/molecule.yml @@ -0,0 +1,2 @@ +platforms: + - name: localhost diff --git a/src/molecule/config.py b/src/molecule/config.py index 2453bd695..ba60d939b 100644 --- a/src/molecule/config.py +++ b/src/molecule/config.py @@ -24,6 +24,7 @@ import os import warnings from collections.abc import MutableMapping +from pathlib import Path from uuid import uuid4 from ansible_compat.ports import cache, cached_property @@ -114,6 +115,7 @@ def __init__( self._run_uuid = str(uuid4()) self.project_directory = os.getenv("MOLECULE_PROJECT_DIRECTORY", os.getcwd()) self.runtime = app.runtime + self.scenario_path = Path(molecule_file).parent def after_init(self): self.config = self._reget_config() diff --git a/src/molecule/provisioner/ansible_playbook.py b/src/molecule/provisioner/ansible_playbook.py index 56134abf8..87028627b 100644 --- a/src/molecule/provisioner/ansible_playbook.py +++ b/src/molecule/provisioner/ansible_playbook.py @@ -110,10 +110,12 @@ def execute(self, action_args=None): with warnings.catch_warnings(record=True) as warns: warnings.filterwarnings("default", category=MoleculeRuntimeWarning) self._config.driver.sanity_checks() + cwd = self._config.scenario_path result = util.run_command( cmd=self._ansible_command, env=self._env, debug=self._config.debug, + cwd=cwd, ) if result.returncode != 0: diff --git a/src/molecule/test/b_functional/test_command.py b/src/molecule/test/b_functional/test_command.py index 7c5a98301..8e86d87c8 100644 --- a/src/molecule/test/b_functional/test_command.py +++ b/src/molecule/test/b_functional/test_command.py @@ -352,3 +352,10 @@ def test_docker() -> None: ).returncode == 0 ) + + +def test_smoke() -> None: + """Execute smoke-test scenario that should spot potentially breaking changes.""" + assert run_command( + ["molecule", "test", "--scenario-name", "smoke"], + )