# Python - ValueError: I/O operation on closed file

**URL:** <https://forum.ansible.com/t/python-valueerror-i-o-operation-on-closed-file/20712>\
**Category:** Ansible Project\
**Created:** [February 29, 2016, 11:51pm UTC](https://forum.ansible.com/t/python-valueerror-i-o-operation-on-closed-file/20712 "2016-02-29T23:51:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [February 29, 2016, 11:51pm UTC](https://forum.ansible.com/t/python-valueerror-i-o-operation-on-closed-file/20712/1 "2016-02-29T23:51:08Z")

</div>

Ansible 2.0.1

When I ssh into a Linux server and run:

`$ ansible-playbook -vvvvvv build.yml`

it runs fine.

But if I ssh into the Linux server and run:

`$ nohup ansible-playbook -vvvvvv build.yml`

or

`$ ansible-playbook -vvvvvv build.yml > output &`

or

`$ nohup ansible-playbook -vvvvvv build.yml > nohup.out`

or

`  
$ nohup ansible-playbook -vvvvvv build.yml \> nohup.out 2\>&1 &

`

it always fails on this task:

`

- name: wait for something to happen  
pause: seconds=15  
`

Like this:

`TASK [wait for something to happen] ************************************************** task path: /build.yml:94 Pausing for 15 seconds (ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort) An exception occurred during task execution. The full traceback is: Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 120, in run res = self._execute() File "/usr/local/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 418, in _execute result = self._handler.run(task_vars=variables) File "/usr/local/lib/python2.7/site-packages/ansible/plugins/action/pause.py", line 123, in run fd = self._connection._new_stdin.fileno() ValueError: I/O operation on closed file fatal: [localhost]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}`

I’m pretty sure it has something to do with STDOUT not being available but I’m not sure of the workaround. Anyone  
have a suggestion?

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [March 1, 2016, 2:09pm UTC](https://forum.ansible.com/t/python-valueerror-i-o-operation-on-closed-file/20712/2 "2016-03-01T14:09:37Z")

</div>

I guess I don’t even understand why the Ansible “pause” module would care about stdout.

J

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [March 1, 2016, 11:02pm UTC](https://forum.ansible.com/t/python-valueerror-i-o-operation-on-closed-file/20712/3 "2016-03-01T23:02:05Z")

</div>

Looking at the code for the pause module:

`  
if seconds is not None:

# setup the alarm handler

signal.signal(signal.SIGALRM, timeout\_handler)  
signal.alarm(seconds)

# show the prompt

display.display(“Pausing for %d seconds” % seconds)  
display.display(“(ctrl+C then ‘C’ = continue early, ctrl+C then ‘A’ = abort)\r”),  
else:  
display.display(prompt)

`

> |
> 
> - |

Even if you only want pause to wait some amount of time, the module still expects STDIN to be available after prompting for ctrl+C.

So, this worked:

`$ nohup ansible-playbook -vvvvvv build.yml 0</dev/null`

It keeps STDIN open but provides no input.

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [March 2, 2016, 8:22pm UTC](https://forum.ansible.com/t/python-valueerror-i-o-operation-on-closed-file/20712/4 "2016-03-02T20:22:57Z")

</div>

Looks like this issue was fixed today: [https://github.com/ansible/ansible/pull/14755](https://github.com/ansible/ansible/pull/14755)
