# How do you send the ENTER keypressed to ansible's expect using shell command.

**URL:** <https://forum.ansible.com/t/how-do-you-send-the-enter-keypressed-to-ansibles-expect-using-shell-command/24331>\
**Category:** Ansible Project\
**Created:** [April 26, 2017, 5:42pm UTC](https://forum.ansible.com/t/how-do-you-send-the-enter-keypressed-to-ansibles-expect-using-shell-command/24331 "2017-04-26T17:42:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nishant\_bawane](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nishant\_bawane](https://forum.ansible.com/u/nishant_bawane)\
**Post date:** [April 26, 2017, 5:42pm UTC](https://forum.ansible.com/t/how-do-you-send-the-enter-keypressed-to-ansibles-expect-using-shell-command/24331/1 "2017-04-26T17:42:32Z")

</div>

Hi below is the command i want to run using shell to create the keys.

shell: ssh [dp794d@130.6.50.132](mailto:dp794d@130.6.50.132) “cd /home/dp794d/.ssh;ssh-keygen”

When i run this command on server, it askes to press the enter 2-3 times and need to enter “y” at pone place. I dont know how this can be achieved using the playbook. How can we manage the manual user input of “enter” keypress with ansible playbook. I need to use the shell module or command module.

---

<div class="post-metadata">

**Author:** ![Uwe\_Sauter](https://avatars.discourse-cdn.com/v4/letter/u/41988e/32.png) [@Uwe\_Sauter](https://forum.ansible.com/u/Uwe_Sauter)\
**Post date:** [April 26, 2017, 5:48pm UTC](https://forum.ansible.com/t/how-do-you-send-the-enter-keypressed-to-ansibles-expect-using-shell-command/24331/2 "2017-04-26T17:48:02Z")

</div>

Why don't you run "ssh-keygen -f \<new\_key\_file\> -t \<rsa or ed25519\> -q -N ''" ?

---

<div class="post-metadata">

**Author:** ![nishant\_bawane](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nishant\_bawane](https://forum.ansible.com/u/nishant_bawane)\
**Post date:** [April 26, 2017, 6:44pm UTC](https://forum.ansible.com/t/how-do-you-send-the-enter-keypressed-to-ansibles-expect-using-shell-command/24331/3 "2017-04-26T18:44:28Z")

</div>

as per suggestion this is what i tried -

- hosts: localhost  
tasks:
- name: “Run ssh commands for remove old id\_rsa files and create new ssh keys”  
shell: ssh-keygen -f /home/dp794d/.ssh/id\_rsa -t rsa -q -N “”  
args:  
creates: /home/dp794d/.ssh/id\_rsa  
with\_lines: cat "/home/capio/ansible/pmossWipm/day1/logs/testIP.txt

below is the error -

failed: [localhost] (item=130.6.50.132) =\> {“changed”: true, “cmd”: “ssh-keygen -f /home/dp794d/.ssh/id\_rsa -t rsa -q -N ""”, “delta”: “0:00:00.248041”, “end”: “2017-04-26 14:41:36.361705”, “failed”: true, “item”: “130.6.50.132”, “rc”: 1, “start”: “2017-04-26 14:41:36.113664”, “stderr”: “open /home/dp794d/.ssh/id\_rsa failed: Permission denied.”, “stdout”: “Saving the key failed: /home/dp794d/.ssh/id\_rsa.”, “stdout\_lines”: [“Saving the key failed: /home/dp794d/.ssh/id\_rsa.”], “warnings”: }

I am doing something wrong, as this is new thing for me. Please suggest

---

<div class="post-metadata">

**Author:** ![Uwe\_Sauter](https://avatars.discourse-cdn.com/v4/letter/u/41988e/32.png) [@Uwe\_Sauter](https://forum.ansible.com/u/Uwe_Sauter)\
**Post date:** [April 26, 2017, 7:11pm UTC](https://forum.ansible.com/t/how-do-you-send-the-enter-keypressed-to-ansibles-expect-using-shell-command/24331/4 "2017-04-26T19:11:07Z")

</div>

Waht are you trying to achieve with "with\_lines: …"?

"with\_lines" is mentioned in the "Loops" documentation [1] but I never used this myself.

But with every loop in Ansible, you somewhere need an {{ item }} in your task definition or else Ansible won't know, where to use the item that comes from one of the "with\_XXXX" parameters.

Do you really want to do a repeating task here?

[1] [http://docs.ansible.com/ansible/playbooks\_loops.html#iterating-over-the-results-of-a-program-execution](http://docs.ansible.com/ansible/playbooks_loops.html#iterating-over-the-results-of-a-program-execution)

---

<div class="post-metadata">

**Author:** ![Uwe\_Sauter](https://avatars.discourse-cdn.com/v4/letter/u/41988e/32.png) [@Uwe\_Sauter](https://forum.ansible.com/u/Uwe_Sauter)\
**Post date:** [April 26, 2017, 7:15pm UTC](https://forum.ansible.com/t/how-do-you-send-the-enter-keypressed-to-ansibles-expect-using-shell-command/24331/5 "2017-04-26T19:15:37Z")

</div>

Running the following playbook on localhost

---

<div class="post-metadata">

**Author:** ![nishant\_bawane](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nishant\_bawane](https://forum.ansible.com/u/nishant_bawane)\
**Post date:** [April 27, 2017, 7:06pm UTC](https://forum.ansible.com/t/how-do-you-send-the-enter-keypressed-to-ansibles-expect-using-shell-command/24331/6 "2017-04-27T19:06:59Z")

</div>

Thanks for the help, it worked!!
