0

I'm trying to follow this solution to add use the shell module and ssh-keyscan to add a key to my known_hosts file of a newly created EC2 instance.

After trying to do this multiple ways as listed on that question I eventually ran just the ssh-keyscan command using the shell module without the append. I am getting no output from this task:

- name: accept new ssh fingerprints                                         
  shell: ssh-keyscan -H {{ item.public_ip }}
  args:
    executable: /bin/bash     
  with_items: "{{ ec2.instances }}"
  register: keyscan
- debug: var=keyscan

Debug here shows nothing in stdout and stdout_lines and nothing in stderr and stderr_lines

Note: I tried running this with the bash as the executable shown after reading that the shell module defaults to /bin/sh which is the dash shell on my Linux Mint VirtualBox. But it's the same regardless.

I have tested the shell command with the following task and I see the proper output in stdout and stdout_lines:

- name: test the shell
  shell: echo hello
  args:
    executable: /bin/bash
  register: hello
- debug: var=hello

What is going on here? Running ssh-keyscan in a terminal (not through Ansible) works as expected.

EDIT: Looking at the raw_params output from debug shows ssh-keyscan -H x.x.x.x and copying and pasting this into the terminal works as expected.

darkwing
  • 491
  • 5
  • 15
  • So what is **the exact command** that Ansible executes? And what is the result when you run this exact command interactively? Isn't it faster and easier to check the realty on your system than on StackOverflow. – techraf Nov 07 '17 at 23:13
  • I have already looked at the raw_params output in debug which runs `ssh-keyscan -H x.x.x.x` and copied and pasted this into the terminal and had it work as expected – darkwing Nov 07 '17 at 23:33
  • Maybe you had looked, but no one on SO did, so why do you expect others to know? – techraf Nov 07 '17 at 23:34
  • I didn't realize that wasn't clear and didn't expect others to know... sorry, I edited the question – darkwing Nov 07 '17 at 23:39
  • No. That adds nothing. Voting to close. – techraf Nov 07 '17 at 23:40
  • 1
    https://meta.stackoverflow.com/questions/251758/why-is-stack-overflow-so-negative-of-late https://meta.stackexchange.com/questions/9953/could-we-please-be-a-bit-nicer-to-new-users – darkwing Nov 08 '17 at 15:42

1 Answers1

0

The answer is that it doesn't work the first time. While researching another method I stumbled across the retries keyword in ansible that allows a retry of whatever command. I tried this and on attempt number 2 in the retry loop it is working.

darkwing
  • 491
  • 5
  • 15