How to set host_key_checking=false in ansible inventory file?

前端 未结 6 538
清歌不尽
清歌不尽 2020-12-12 12:10

I would like to use ansible-playbook command instead of \'vagrant provision\'. However setting host_key_checking=false in the ho

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 13:01

    Yes, you can set this on the inventory/host level.

    With an already accepted answer present, I think this is a better answer to the question on how to handle this on the inventory level. I consider this more secure by isolating this insecure setting to the hosts required for this (e.g. test systems, local development machines).

    What you can do at the inventory level is add

    ansible_ssh_common_args='-o StrictHostKeyChecking=no'
    

    or

    ansible_ssh_extra_args='-o StrictHostKeyChecking=no'
    

    to your host definition (see Ansible Behavioral Inventory Parameters).

    This will work provided you use the ssh connection type, not paramiko or something else).

    For example, a Vagrant host definition would look like…

    vagrant ansible_port=2222 ansible_host=127.0.0.1 ansible_ssh_common_args='-o StrictHostKeyChecking=no'
    

    or

    vagrant ansible_port=2222 ansible_host=127.0.0.1 ansible_ssh_extra_args='-o StrictHostKeyChecking=no'
    

    Running Ansible will then be successful without changing any environment variable.

    $ ansible vagrant -i  -m ping
    vagrant | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    

    In case you want to do this for a group of hosts, here's a suggestion to make it a supplemental group var for an existing group like this:

    [mytestsystems]
    test[01:99].example.tld
    
    [insecuressh:children]
    mytestsystems
    
    [insecuressh:vars]
    ansible_ssh_common_args='-o StrictHostKeyChecking=no'
    

提交回复
热议问题