Skip to content

Instantly share code, notes, and snippets.

@marshallpierce
Last active July 21, 2016 22:13
Show Gist options
  • Save marshallpierce/a1e77fb6a2b20a6bc31cc593de60e8d7 to your computer and use it in GitHub Desktop.
Save marshallpierce/a1e77fb6a2b20a6bc31cc593de60e8d7 to your computer and use it in GitHub Desktop.
Ansible unarchive bug report
ISSUE TYPE
  • Bug Report
COMPONENT NAME

unarchive

ANSIBLE VERSION
ansible 2.1.0.0
  config file = /path/to/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION

Contents of ansible.cfg:

[defaults]
inventory = contrib/ec2.py
vault_password_file = .vault_password
hash_behaviour = merge

[ssh_connection]
pipelining = True
OS / ENVIRONMENT

Gentoo x64 Linux

SUMMARY

The error message formatting in unarchive doesn't seem to handle string file modes properly, leading to a TypeError at runtime.

STEPS TO REPRODUCE

While executing this task:

- name: install packer
  tags: packer
  unarchive:
    copy: false
    src: https://releases.hashicorp.com/packer/0.10.1/packer_0.10.1_linux_amd64.zip
    dest: /usr/local/bin
    owner: root
    group: root
    mode: 'u=rwx,g=rx,o=rx'

the following occurs:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: %o format: a number is required, not str
fatal: [jenkins-node]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):
  File \"/tmp/ansible_5KjD3R/ansible_module_unarchive.py\", line 751, in <module>
    main()
  File \"/tmp/ansible_5KjD3R/ansible_module_unarchive.py\", line 711, in main
    check_results = handler.is_unarchived()
  File \"/tmp/ansible_5KjD3R/ansible_module_unarchive.py\", line 397, in is_unarchived
    err += 'Path %s differs in permissions (%o vs %o)\
' % (path, self.file_args['mode'], stat.S_IMODE(st.st_mode))
TypeError: %o format: a number is required, not str
", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}

I haven't figured out why exactly the code ended up in that particular case, but the code in question is in unarchive.py, which looks like this:

err += 'Path %s differs in permissions (%o vs %o)\n' % (path, mode, stat.S_IMODE(st.st_mode))

%o is for signed octal values according to https://docs.python.org/2/library/stdtypes.html#string-formatting, so I'm guessing that mode is the string from the original task definition, which is causing the TypeError.

EXPECTED RESULTS

It works fine if I use numeric file modes (e.g. 0755 here), so it should do that for string modes too.

ACTUAL RESULTS
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: %o format: a number is required, not str
fatal: [jenkins-node]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):
  File \"/tmp/ansible_5KjD3R/ansible_module_unarchive.py\", line 751, in <module>
    main()
  File \"/tmp/ansible_5KjD3R/ansible_module_unarchive.py\", line 711, in main
    check_results = handler.is_unarchived()
  File \"/tmp/ansible_5KjD3R/ansible_module_unarchive.py\", line 397, in is_unarchived
    err += 'Path %s differs in permissions (%o vs %o)\
' % (path, self.file_args['mode'], stat.S_IMODE(st.st_mode))
TypeError: %o format: a number is required, not str
", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment