corrupted output when running script module

Hello,

I’m having a problem with Ansible 1.8.4, which I’m running on a Macintosh to
remotely configure a host running on Amazon AWS. The command I’m using
to run a playbook is as follows:

ansible-playbook playbooks/site.yml -l ec2-54-242-9-223.compute-1.amazonaws.com -v -s -i inventory/qa -e {"zoo_stage":"qa","release_name":"20150602222150"} --skip-tags skip_during_zoo_boot

The playbook includes the following content:

  • name: run decide_istore_action script
    script: …/bin/decide_istore_action {{ instance_store_devices|join(" ") }} 2> /tmp/dave_debug_stderr | tee /tmp/dave_debug_stdout
    register: istore_action

  • debug: msg=“istore action is ==>{{ istore_action.stdout }}<==”

The script writes only a single character ‘F’ (upper case letter F) to standard
output, which I am able to verify by inspecting the contents of
/tmp/dave_debug_stdout on the AWS host. However I see the following output
when the playbook executes:

TASK: [run decide_istore_action script] ***************************************
changed: [minsk.scholarific.us] => {“changed”: true, “rc”: 0, “stderr”: “”, “stdout”: “sudo: unable to resolve host minsk.scholarific.us\r\nsudo: unable to resolve host minsk.scholarific.us\r\nSUDO-SUCCESS-znqxbojxeouzargyysdupmmfyzzbncsy\r\nF”}

TASK: [debug msg=“istore action is ==>{{ istore_action.stdout }}<==”] *********
ok: [minsk.scholarific.us] => {
“msg”: “istore action is ==>sudo: unable to resolve host minsk.scholarific.us\nsudo: unable to resolve host minsk.scholarific.us\nSUDO-SUCCESS-znqxbojxeouzargyysdupmmfyzzbncsy\nF<==”
}

Notice that the ‘F’ character written by the script is preceded by two error
messages and some additional text. Thus it appears that a bug in Ansible is
corrupting my script’s output by injecting extra text before the script’s actual
output. Does this problem look familiar to anyone, or does anyone have ideas
about what may be happening? The hostname minsk.scholarific.us mentioned
in the error message is the name of the EC2 instance, which was created
shortly before the playbook ran. I’m not sure whether the DNS lookup was
attempted on the Mac where the playbook was being executed from, or the
EC2 instance. However, shortly after observing the above behavior I logged
into the EC2 instance and did a DNS lookup, which failed:

dave@minsk:~$ nslookup minsk.scholarific.us
Server: 172.16.0.23
Address: 172.16.0.23#53

** server can’t find minsk.scholarific.us: NXDOMAIN

dave@minsk:~$

After waiting a few minutes I tried the lookup again and it succeeded, so I guess
it took a while for the DNS change to propagate. So this raises two questions:

  1. If the error message is the result of a DNS lookup attempted on the
    EC2 host, why would Ansible be doing a lookup there just to run a local
    command?

  2. Why is the output getting mixed in with my script’s standard output?

Any help anyone may be able to offer is greatly appreciated.

Thanks
Dave

The warning is not from ansible, but from sudo, which ansible is using
at your request.

Sudo is trying to verify the hostname and spurting the message into
stdout, since Ansible is executing your script under sudo it gets both
outputs and cannot distinguish which came from which. The common
solution for this sudo issue is adding the host to dns or /etc/hosts
on the machine, in this case it seems that DNS is being slow to
propagate.

Sadly this error message varies a lot across sudo
installations/versions/etc, so it is not easy to filter out
universally. I'm not sure there is much we can do on the ansible side.

ok thanks