From 6dbc3c63f8db7451b02c8282250e340c1a7f08e6 Mon Sep 17 00:00:00 2001 From: Nicklaus McClendon Date: Tue, 12 Sep 2017 12:01:29 -0500 Subject: [PATCH] Updated pip module to always return changed if venv is created (#24233) * Updated pip module to always return changed if venv is created Fixes #23204 * Add integration test to pip (see #23204) --- lib/ansible/modules/packaging/language/pip.py | 5 ++++- test/integration/targets/pip/tasks/pip.yml | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/packaging/language/pip.py b/lib/ansible/modules/packaging/language/pip.py index a07af562d3b..9dcc0a63c31 100644 --- a/lib/ansible/modules/packaging/language/pip.py +++ b/lib/ansible/modules/packaging/language/pip.py @@ -425,9 +425,10 @@ def main(): out = '' env = module.params['virtualenv'] - + venv_created = False if env: if not os.path.exists(os.path.join(env, 'bin', 'activate')): + venv_created = True if module.check_mode: module.exit_json(changed=True) @@ -566,6 +567,8 @@ def main(): _, out_freeze_after, _ = _get_packages(module, pip, chdir) changed = out_freeze_before != out_freeze_after + changed = changed or venv_created + module.exit_json(changed=changed, cmd=cmd, name=name, version=version, state=state, requirements=requirements, virtualenv=env, stdout=out, stderr=err) diff --git a/test/integration/targets/pip/tasks/pip.yml b/test/integration/targets/pip/tasks/pip.yml index fe7c7da0804..44c00a786b8 100644 --- a/test/integration/targets/pip/tasks/pip.yml +++ b/test/integration/targets/pip/tasks/pip.yml @@ -166,3 +166,20 @@ assert: that: - "not q_check_mode.changed" + +# ansible#23204 +- name: ensure is a fresh virtualenv + file: + state: absent + name: "{{ output_dir }}/pipenv" + +- name: install pip throught pip into fresh virtualenv + pip: + name: pip + virtualenv: "{{ output_dir }}/pipenv" + register: pip_install_venv + +- name: make sure pip in fresh virtualenv report changed + assert: + that: + - "pip_install_venv.changed"