Ansible – Failing playbook with Error: AttributeError: ‘str’ object has no attribute ‘format’

Published on Author gryzli

The problem

My playbook task was looking like this:

- name: Execute simple command
  command: /some/simple/commmand  

The error persisted even after changing “command:” to “shell:”


If you happen to hit ansible error like this:

failed: [some_host] => {“failed”: true, “parsed”: false}
Traceback (most recent call last):
File “/root/.ansible/tmp/ansible-tmp-1425474902.88-6397676824195/command”, line 129, in ?
PARAM_REGEX = re.compile(
AttributeError: ‘str’ object has no attribute ‘format’


Then most likely your remote host is running old Python under 2.6.x. For example in my case I was using Python 2.4 on the remote host.

In Python versions below 2.6.x , the “format” method of “string” is NOT available.

The Solution

If your remote host is using Python 2.4 and you don’t want to update it (which is the recommended fix), then you can use the “raw” action:

# This runs successfully 
- name: Execute simple command
  raw: /some/simple/commmand