Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.9.10: UnboundLocalError: local variable 'module_style' referenced before assignment #70168

Closed
resmo opened this issue Jun 19, 2020 · 7 comments · Fixed by #70171 or #70293
Closed

2.9.10: UnboundLocalError: local variable 'module_style' referenced before assignment #70168

resmo opened this issue Jun 19, 2020 · 7 comments · Fixed by #70171 or #70293
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@resmo
Copy link
Contributor

resmo commented Jun 19, 2020

SUMMARY

after upgrade from 2.9.9 to 2.9.10 we see an exception in a task using lineinfile delegate_facts=true

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
2.9.10
CONFIGURATION
ANSIBLE_NOCOWS(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = True
ANSIBLE_PIPELINING(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
CACHE_PLUGIN(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = .cache/facts
CACHE_PLUGIN_TIMEOUT(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = 86400
COLLECTIONS_PATHS(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = [u'/home/rmoser/Projects/puzzle/ansible-puzzle/collections_galaxy']
CONDITIONAL_BARE_VARS(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = False
DEFAULT_BECOME(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = True
DEFAULT_BECOME_ASK_PASS(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = False
DEFAULT_BECOME_METHOD(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = sudo
DEFAULT_BECOME_USER(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = root
DEFAULT_FORKS(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = 20
DEFAULT_GATHERING(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = [u'/home/rmoser/Projects/puzzle/ansible-puzzle/inventories/cloud_staging']
DEFAULT_LOAD_CALLBACK_PLUGINS(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = False
DEFAULT_MANAGED_STR(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = Warning: File is managed by Ansible
DEFAULT_PRIVATE_KEY_FILE(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = /home/rmoser/.ssh/id_rsa
DEFAULT_REMOTE_USER(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = ansible
DEFAULT_ROLES_PATH(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = [u'/home/rmoser/Projects/puzzle/ansible-puzzle/roles_galaxy', u'/home/rmoser/Projects/puzzle/ansible-puzzle/roles']
DEFAULT_STDOUT_CALLBACK(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = yaml
HOST_KEY_CHECKING(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = True
INTERPRETER_PYTHON(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = auto
RETRY_FILES_ENABLED(/home/rmoser/Projects/puzzle/ansible-puzzle/ansible.cfg) = False

OS / ENVIRONMENT
STEPS TO REPRODUCE
---
- hosts: my.example.com
  gather_facts: yes
  tasks:
  - name: make something
    delegate_facts: True
    delegate_to: other.example.com
    lineinfile:
      path: /tmp/foo.txt
      regexp: '^Listen '
      insertafter: '^#Listen '
      line: Listen 8080
EXPECTED RESULTS
ACTUAL RESULTS
The full traceback is:
Traceback (most recent call last):
  File "/home/rmoser/Projects/resmo/ansible/lib/ansible/executor/task_executor.py", line 146, in run
    res = self._execute()
  File "/home/rmoser/Projects/resmo/ansible/lib/ansible/executor/task_executor.py", line 654, in _execute
    result = self._handler.run(task_vars=variables)
  File "/home/rmoser/Projects/resmo/ansible/lib/ansible/plugins/action/normal.py", line 46, in run
    result = merge_hash(result, self._execute_module(task_vars=task_vars, wrap_async=wrap_async))
  File "/home/rmoser/Projects/resmo/ansible/lib/ansible/plugins/action/__init__.py", line 831, in _execute_module
    (module_style, shebang, module_data, module_path) = self._configure_module(module_name=module_name, module_args=module_args, task_vars=task_vars)
  File "/home/rmoser/Projects/resmo/ansible/lib/ansible/plugins/action/__init__.py", line 244, in _configure_module
    return (module_style, module_shebang, module_data, module_path)
UnboundLocalError: local variable 'module_style' referenced before assignment
fatal: [server.example.com]: FAILED! => 
  msg: Unexpected failure during module execution.
  stdout: ''

@mkrizek
Copy link
Contributor

mkrizek commented Jun 19, 2020

I couldn't reproduce this with an arbitrary lineinfile task. We'll need you to provide a minimal reproducer.

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels Jun 19, 2020
@resmo
Copy link
Contributor Author

resmo commented Jun 19, 2020

@mkrizek I added a reproducer. It seems related to delegate_facts=true

@mkrizek
Copy link
Contributor

mkrizek commented Jun 19, 2020

Sounds like this might be related to #69604.

cc @bcoca

@srgvg
Copy link
Contributor

srgvg commented Jun 19, 2020

Can confirm, we have the same problem, though it only triggers in particular case (localhost -> localhost)

Playbook:

# this might seem as a complex construct for just runnig setup/facts gathering on the `all` group,                        
# but this way, we are sure to have all the facts of all the hosts even if the play was run on a `--limit`ed set of hosts!
- name: Setup facts
  hosts: localhost
  tasks:
  ┊ - name: Gather facts from hosts
  ┊ ┊ setup:
  ┊ ┊ ┊ gather_subset: "all"
  ┊ ┊ delegate_to: "{{ item }}"
  ┊ ┊ delegate_facts: True
  ┊ ┊ with_items: "{{ groups['all'] }}"
  tags:
  ┊ - always

Results:

20200619143809

@mkrizek
Copy link
Contributor

mkrizek commented Jun 19, 2020

Since we now pass use_vars instead of task_vars to modify_module, we need to update information in use_vars for the next iteration too. The following makes the problem go away:

diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py
index 83c7715d3e..62a185a3fd 100644
--- a/lib/ansible/plugins/action/__init__.py
+++ b/lib/ansible/plugins/action/__init__.py
@@ -249,7 +249,9 @@ class ActionBase(with_metaclass(ABCMeta, object)):
                     # store in local task_vars facts collection for the retry and any other usages in this worker
                     if use_vars.get('ansible_facts') is None:
                         task_vars['ansible_facts'] = {}
+                        use_vars['ansible_facts'] = {}
                     task_vars['ansible_facts'][discovered_key] = self._discovered_interpreter
+                    use_vars['ansible_facts'][discovered_key] = self._discovered_interpreter
                     # preserve this so _execute_module can propagate back to controller as a fact
                     self._discovered_interpreter_key = discovered_key
                 else:

The similar would need to be changed in the else branch as well. I am not sure if changing task_vars is needed though, or if changing all occurrences of task_vars to use_vars would be the fix.

mkrizek added a commit to mkrizek/ansible that referenced this issue Jun 19, 2020
@ansibot ansibot added the has_pr This issue has an associated PR. label Jun 19, 2020
guits added a commit to ceph/ceph-ansible that referenced this issue Jun 19, 2020
ansible 2.9.10 seems to have introduced a bug.

See ansible/ansible#70168

This commit excludes this version from ceph-ansible testing

Signed-off-by: Guillaume Abrioux <[email protected]>
guits added a commit to ceph/ceph-ansible that referenced this issue Jun 19, 2020
ansible 2.9.10 seems to have introduced a bug.

See ansible/ansible#70168

This commit excludes this version from ceph-ansible testing

Signed-off-by: Guillaume Abrioux <[email protected]>
guits added a commit to ceph/ceph-ansible that referenced this issue Jun 19, 2020
ansible 2.9.10 seems to have introduced a bug.

See ansible/ansible#70168

This commit excludes this version from ceph-ansible testing

Signed-off-by: Guillaume Abrioux <[email protected]>
guits added a commit to ceph/ceph-ansible that referenced this issue Jun 19, 2020
ansible 2.9.10 seems to have introduced a bug.

See ansible/ansible#70168

This commit excludes this version from ceph-ansible requirements.

Signed-off-by: Guillaume Abrioux <[email protected]>
dsavineau pushed a commit to ceph/ceph-ansible that referenced this issue Jun 19, 2020
ansible 2.9.10 seems to have introduced a bug.

See ansible/ansible#70168

This commit excludes this version from ceph-ansible requirements.

Signed-off-by: Guillaume Abrioux <[email protected]>
mergify bot pushed a commit to ceph/ceph-ansible that referenced this issue Jun 19, 2020
ansible 2.9.10 seems to have introduced a bug.

See ansible/ansible#70168

This commit excludes this version from ceph-ansible requirements.

Signed-off-by: Guillaume Abrioux <[email protected]>
(cherry picked from commit 1525990)
dsavineau pushed a commit to ceph/ceph-ansible that referenced this issue Jun 20, 2020
ansible 2.9.10 seems to have introduced a bug.

See ansible/ansible#70168

This commit excludes this version from ceph-ansible requirements.

Signed-off-by: Guillaume Abrioux <[email protected]>
(cherry picked from commit 1525990)
bcoca pushed a commit that referenced this issue Jun 22, 2020
* Fix storing local task_vars facts for the retry

Fixes #70168
mkrizek added a commit to mkrizek/ansible that referenced this issue Jun 22, 2020
mkrizek added a commit to mkrizek/ansible that referenced this issue Jun 22, 2020
* Fix storing local task_vars facts for the retry

Fixes ansible#70168

(cherry picked from commit eaf6086)
dsavineau pushed a commit to ceph/ceph-ansible that referenced this issue Jun 22, 2020
ansible 2.9.10 seems to have introduced a bug.

See ansible/ansible#70168

This commit excludes this version from ceph-ansible requirements.

Signed-off-by: Guillaume Abrioux <[email protected]>
(cherry picked from commit 1525990)
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Jun 22, 2020
@samdoran
Copy link
Contributor

Reopening since the fix for this was reverted in #70272.

@samdoran samdoran reopened this Jun 24, 2020
@gfidente
Copy link

gfidente commented Jun 25, 2020

as per IRC chat in #ansible-devel :

@mkrizek iirc the issue was related to using delegate_to AND delegate_facts AND ansible_python_interpreter not being explicitly set (set set to auto)

that explains why it's seen in ceph-ansible ci but we aren't seeing it in tripleo ci; in tripleo we forcibly set ansible_python_interpreter [1]

  1. https://github.com/openstack/tripleo-heat-templates/blob/stable/train/common/deploy-steps.j2#L1091

mkrizek added a commit to mkrizek/ansible that referenced this issue Jun 25, 2020
* Fix storing local task_vars facts for the retry

Fixes ansible#70168

(cherry picked from commit eaf6086)
mattclay added a commit to mattclay/ansible that referenced this issue Jun 25, 2020
bcoca pushed a commit to bcoca/ansible that referenced this issue Jun 25, 2020
* Fix storing local task_vars facts for the retry

Fixes ansible#70168
sf-project-io pushed a commit to redhat-cip/dci-openstack-agent that referenced this issue Jun 26, 2020
Discard ansible-2.9.10 because it has issues with delegate_facts that
block us ansible/ansible#70168

Fix python shebang for el8 rpms

Change-Id: If2ca8ab58fc5dfeb82e6b48998d0b66128ad2f55
Depends-On: I8b86786d866193d9e399ea0c50e9546d024a0059
Depends-On: I1594f6dd0c20327492ef5acb32305af12d47c0f7
mkrizek added a commit that referenced this issue Jun 30, 2020
Fixes #70168

ci_complete

Co-authored-by: Brian Coca <[email protected]>
Co-authored-by: Matt Clay <[email protected]>
mkrizek added a commit to mkrizek/ansible that referenced this issue Jun 30, 2020
Fixes ansible#70168

ci_complete

Co-authored-by: Brian Coca <[email protected]>
Co-authored-by: Matt Clay <[email protected]>
(cherry picked from commit b05e00e)
mkrizek added a commit to mkrizek/ansible that referenced this issue Jun 30, 2020
Fixes ansible#70168

ci_complete

Co-authored-by: Brian Coca <[email protected]>
Co-authored-by: Matt Clay <[email protected]>
(cherry picked from commit b05e00e)
nitzmahone pushed a commit that referenced this issue Jul 17, 2020
Fixes #70168

ci_complete

Co-authored-by: Brian Coca <[email protected]>
Co-authored-by: Matt Clay <[email protected]>
(cherry picked from commit b05e00e)
nitzmahone pushed a commit that referenced this issue Jul 17, 2020
Fixes #70168

ci_complete

Co-authored-by: Brian Coca <[email protected]>
Co-authored-by: Matt Clay <[email protected]>
(cherry picked from commit b05e00e)
@ansible ansible locked and limited conversation to collaborators Jul 28, 2020
ciis0 pushed a commit to atosorigin/ansible that referenced this issue Apr 12, 2021
* Fix storing local task_vars facts for the retry

Fixes ansible#70168
ciis0 pushed a commit to atosorigin/ansible that referenced this issue May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
7 participants