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

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

shell: ssh 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.

Why don't you run "ssh-keygen -f <new_key_file> -t <rsa or ed25519> -q -N ''" ?

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

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

Running the following playbook on localhost

Thanks for the help, it worked!!