15

I'm running an Ansible playbook with a subtle hack to work on an arbitrary port forwarded port (so I can use one machine with no direct access to lots of machines).

I've got a pre-task to change the ansible_port variable, so then when I start running my real tasks and roles, I get prompted to accept the hostkeys for localhost on some random port.

Because I am naive and don't care about security, I would like ssh to auto-accept and redirect to /dev/null (or another file for logging).

Is this possible?

  • You can do it through ssh options you pass to the ansible config. – Jiri Klouda Mar 30 '17 at 15:23
21

This is typically done by setting the following value in ansible.cfg:

[defaults]
host_key_checking = False

If you don't want to modify ansible.cfg you can set an environment variable like so:

export ANSIBLE_HOST_KEY_CHECKING=False

Source: http://docs.ansible.com/ansible/intro_getting_started.html#host-key-checking

19

In your ansible.cfg file you need to add the following line:

ssh_args = -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no

You could also add those options in your ~/.ssh/config on every machine from which you run it something like this:

Host *
   StrictHostKeyChecking no
   UserKnownHostsFile=/dev/null
  • 1
    This should work. Also, look at the ansible.cfg file for more settings :) – Dawny33 Mar 30 '17 at 16:32
  • +1 for Dawny's addition, because those using Paramiko will need to use ansible.cfg – Woodland Hunter Mar 30 '17 at 17:19
  • 1
    Is there an appropriate way to set that inside the playbook? I've tried ansible_ssh_common_args and ansible_ssh_extra_args and it doesn't override what I've got in the ansible.cfg. I've got an ansible.cfg that I use for everything else and would rather just override those parameters for this type of playbook than copy it just to make that change. – Peter Turner Mar 30 '17 at 18:03
  • 3
    I can't speak to those variables, Peter, but you could put a modified ansible.cfg in the directory with this playbook, and it will take precedence. – Woodland Hunter Mar 30 '17 at 21:37
  • 1
    UserKnownHostsFile=/dev/null completly break ssh security – mmv-ru Feb 3 '18 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.