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

touch a file in dry-run gives an error in ansible-2.6.0 #42190

Closed
dnmvisser opened this issue Jul 2, 2018 · 2 comments
Closed

touch a file in dry-run gives an error in ansible-2.6.0 #42190

dnmvisser opened this issue Jul 2, 2018 · 2 comments
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@dnmvisser
Copy link
Contributor

SUMMARY

Trying to use the file module's touch state in dry-run mode gives UnboundLocalError: local variable 'diff' referenced before assignment in 2.6.0.
In 2.5.5 this worked OK.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

file

ANSIBLE VERSION
ansible 2.6.0
  config file = /Users/someuser/ansible/ansible.cfg
  configured module search path = [u'/Users/someuser/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/someuser/.virtualenvs/ansible-2.6.0/lib/python2.7/site-packages/ansible
  executable location = /Users/someuser/.virtualenvs/ansible-2.6.0/bin/ansible
  python version = 2.7.15 (default, May  1 2018, 16:44:08) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
CONFIGURATION

ALLOW_WORLD_READABLE_TMPFILES(/Users/username/ansible/ansible.cfg) = True
ANSIBLE_PIPELINING(/Users/username/ansible/ansible.cfg) = True
ANSIBLE_SSH_CONTROL_PATH(/Users/username/ansible/ansible.cfg) = ~/.ssh/cm/%%C
CACHE_PLUGIN(/Users/username/ansible/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/Users/username/ansible/ansible.cfg) = ~/.ansible/cached_facts
CACHE_PLUGIN_TIMEOUT(/Users/username/ansible/ansible.cfg) = 600
DEFAULT_FILTER_PLUGIN_PATH(/Users/username/ansible/ansible.cfg) = [u'/Users/username/ansible/filters']
DEFAULT_FORKS(/Users/username/ansible/ansible.cfg) = 25
DEFAULT_GATHERING(/Users/username/ansible/ansible.cfg) = smart
DEFAULT_HOST_LIST(/Users/username/ansible/ansible.cfg) = [u'/Users/username/ansible/inventory.yml']
DEFAULT_JINJA2_EXTENSIONS(/Users/username/ansible/ansible.cfg) = jinja2.ext.loopcontrols
DEFAULT_NO_TARGET_SYSLOG(/Users/username/ansible/ansible.cfg) = True
DEFAULT_ROLES_PATH(/Users/username/ansible/ansible.cfg) = [u'/Users/username/ansible/roles']
DEFAULT_TIMEOUT(/Users/username/ansible/ansible.cfg) = 20
DEFAULT_TRANSPORT(/Users/username/ansible/ansible.cfg) = ssh
DEFAULT_VAULT_PASSWORD_FILE(/Users/username/ansible/ansible.cfg) = /Users/username/ansible/files/open_vault.sh
RETRY_FILES_ENABLED(/Users/username/ansible/ansible.cfg) = False

OS / ENVIRONMENT

N/A

STEPS TO REPRODUCE
---
- name: Test playbook
  hosts: some.host.name

  tasks:
    - name: Touch some file
      file:
        dest: /tmp/test
        state: touch
EXPECTED RESULTS
(ansible-2.5.5) username@geant-ams-049:~/ansible$ ansible-playbook playbooks/test1.yml -CD -vvv
ansible-playbook 2.5.5
  config file = /Users/username/ansible/ansible.cfg
  configured module search path = [u'/Users/username/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/username/.virtualenvs/ansible-2.5.5/lib/python2.7/site-packages/ansible
  executable location = /Users/username/.virtualenvs/ansible-2.5.5/bin/ansible-playbook
  python version = 2.7.15 (default, May  1 2018, 16:44:08) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
Using /Users/username/ansible/ansible.cfg as config file
Parsed /Users/username/ansible/inventory.yml inventory source with ini plugin

PLAYBOOK: test1.yml **************************************************************************************************************************************
1 plays in playbooks/test1.yml

PLAY [Test playbook] *************************************************************************************************************************************
META: ran handlers

TASK [Touch some file] ***********************************************************************************************************************************
task path: /Users/username/ansible/playbooks/test1.yml:6
Using module file /Users/username/.virtualenvs/ansible-2.5.5/lib/python2.7/site-packages/ansible/modules/files/file.py
<some.host.name> ESTABLISH SSH CONNECTION FOR USER: None
<some.host.name> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=20 -o 'ControlPath=~/.ssh/cm/%C' some.host.name '/bin/sh -c '"'"'/usr/bin/python && sleep 0'"'"''
<some.host.name> (0, '\n{"group": "localadm", "uid": 1002, "dest": "/tmp/test", "changed": true, "owner": "visser", "state": "file", "gid": 1002, "mode": "0644", "invocation": {"module_args": {"directory_mode": null, "force": false, "remote_src": null, "path": "/tmp/test", "owner": null, "follow": true, "group": null, "unsafe_writes": null, "state": "touch", "content": null, "serole": null, "diff_peek": null, "setype": null, "dest": "/tmp/test", "selevel": null, "original_basename": null, "regexp": null, "validate": null, "src": null, "seuser": null, "recurse": false, "delimiter": null, "mode": null, "attributes": null, "backup": null}}, "diff": {"after": {"path": "/tmp/test", "state": "touch"}, "before": {"path": "/tmp/test", "state": "file"}}, "size": 0}\n', '')
--- before
+++ after
@@ -1,4 +1,4 @@
 {
     "path": "/tmp/test",
-    "state": "file"
+    "state": "touch"
 }

changed: [some.host.name] => {
    "changed": true, 
    "dest": "/tmp/test", 
    "diff": {
        "after": {
            "path": "/tmp/test", 
            "state": "touch"
        }, 
        "before": {
            "path": "/tmp/test", 
            "state": "file"
        }
    }, 
    "gid": 1002, 
    "group": "localadm", 
    "invocation": {
        "module_args": {
            "attributes": null, 
            "backup": null, 
            "content": null, 
            "delimiter": null, 
            "dest": "/tmp/test", 
            "diff_peek": null, 
            "directory_mode": null, 
            "follow": true, 
            "force": false, 
            "group": null, 
            "mode": null, 
            "original_basename": null, 
            "owner": null, 
            "path": "/tmp/test", 
            "recurse": false, 
            "regexp": null, 
            "remote_src": null, 
            "selevel": null, 
            "serole": null, 
            "setype": null, 
            "seuser": null, 
            "src": null, 
            "state": "touch", 
            "unsafe_writes": null, 
            "validate": null
        }
    }, 
    "mode": "0644", 
    "owner": "visser", 
    "size": 0, 
    "state": "file", 
    "uid": 1002
}
META: ran handlers
META: ran handlers

PLAY RECAP ***********************************************************************************************************************************************
some.host.name           : ok=1    changed=1    unreachable=0    failed=0   

ACTUAL RESULTS
(ansible-2.6.0) username@geant-ams-049:~/ansible$ ansible-playbook playbooks/test1.yml -CD -vvv
ansible-playbook 2.6.0
  config file = /Users/username/ansible/ansible.cfg
  configured module search path = [u'/Users/username/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/username/.virtualenvs/ansible-2.6.0/lib/python2.7/site-packages/ansible
  executable location = /Users/username/.virtualenvs/ansible-2.6.0/bin/ansible-playbook
  python version = 2.7.15 (default, May  1 2018, 16:44:08) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
Using /Users/username/ansible/ansible.cfg as config file
Parsed /Users/username/ansible/inventory.yml inventory source with ini plugin

PLAYBOOK: test1.yml **************************************************************************************************************************************
1 plays in playbooks/test1.yml

PLAY [Test playbook] *************************************************************************************************************************************
META: ran handlers

TASK [Touch some file] ***********************************************************************************************************************************
task path: /Users/username/ansible/playbooks/test1.yml:6
Using module file /Users/username/.virtualenvs/ansible-2.6.0/lib/python2.7/site-packages/ansible/modules/files/file.py
<some.host.name> ESTABLISH SSH CONNECTION FOR USER: None
<some.host.name> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=20 -o 'ControlPath=~/.ssh/cm/%C' some.host.name '/bin/sh -c '"'"'/usr/bin/python && sleep 0'"'"''
<some.host.name> (1, '', 'Traceback (most recent call last):\n  File "/tmp/ansible_eWqv0v/ansible_module_file.py", line 739, in <module>\n    main()\n  File "/tmp/ansible_eWqv0v/ansible_module_file.py", line 731, in main\n    result = execute_touch(path, follow)\n  File "/tmp/ansible_eWqv0v/ansible_module_file.py", line 373, in execute_touch\n    return {\'dest\': path, \'changed\': True, \'diff\': diff}\nUnboundLocalError: local variable \'diff\' referenced before assignment\n')
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_eWqv0v/ansible_module_file.py", line 739, in <module>
    main()
  File "/tmp/ansible_eWqv0v/ansible_module_file.py", line 731, in main
    result = execute_touch(path, follow)
  File "/tmp/ansible_eWqv0v/ansible_module_file.py", line 373, in execute_touch
    return {'dest': path, 'changed': True, 'diff': diff}
UnboundLocalError: local variable 'diff' referenced before assignment

fatal: [some.host.name]: FAILED! => { 
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_eWqv0v/ansible_module_file.py\", line 739, in <module>\n    main()\n  File \"/tmp/ansible_eWqv0v/ansible_module_file.py\", line 731, in main\n    result = execute_touch(path, follow)\n  File \"/tmp/ansible_eWqv0v/ansible_module_file.py\", line 373, in execute_touch\n    return {'dest': path, 'changed': True, 'diff': diff}\nUnboundLocalError: local variable 'diff' referenced before assignment\n", 
    "module_stdout": "",
    "msg": "MODULE FAILURE", 
    "rc": 1
}

PLAY RECAP ***********************************************************************************************************************************************
some.host.name           : ok=0    changed=0    unreachable=0    failed=1  

@ansibot
Copy link
Contributor

ansibot commented Jul 2, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. 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 Jul 2, 2018
@s-hertel
Copy link
Contributor

s-hertel commented Jul 2, 2018

This was fixed in devel in 22a6927 and will be backported to 2.6.1 in #42129.

@s-hertel s-hertel closed this as completed Jul 2, 2018
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Jul 5, 2018
@ansible ansible locked and limited conversation to collaborators Jul 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

No branches or pull requests

4 participants