Skip to content

Commit

Permalink
chore: Disable host ssh key checking via ANSIBLE_HOST_KEY_CHECKING
Browse files Browse the repository at this point in the history
Instead using "ansible_ssh_extra_args" to disable host key check, use
the common env variable to disable it.

Signed-off-by: Yihuang Yu <[email protected]>
  • Loading branch information
PaulYuuu committed Jul 30, 2024
1 parent fc9e1e8 commit 58f91a6
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 18 deletions.
6 changes: 3 additions & 3 deletions provider/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def _generate_cmd(self, extra_vars=None, addl_opts=None):
:param addl_opts: Other ansible-playbook common options.
:return: The generated ansible-playbook command line.
"""
playbook_cmd_options = []
playbook_cmd_options = ["ANSIBLE_HOST_KEY_CHECKING=false"]
if self.callback_plugin:
playbook_cmd_options = [
'ANSIBLE_STDOUT_CALLBACK={}'.format(self.callback_plugin)]
playbook_cmd_options.append(
'ANSIBLE_STDOUT_CALLBACK={}'.format(self.callback_plugin))
playbook_cmd_options.extend([self.program,
self.site_yml,
'-i {}'.format(self.inventory)])
Expand Down
4 changes: 1 addition & 3 deletions qemu/tests/ansible_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def run(test, params, env):
ansible_callback_plugin = params.get("ansible_callback_plugin")
ansible_connection_plugin = params.get("ansible_connection_plugin")
ansible_addl_opts = params.get("ansible_addl_opts", "")
ansible_ssh_extra_args = params["ansible_ssh_extra_args"]
ansible_extra_vars = params.get("ansible_extra_vars", "{}")
custom_extra_vars = params.objects("custom_extra_vars")
playbook_repo = params["playbook_repo"]
Expand All @@ -60,8 +59,7 @@ def run(test, params, env):

error_context.base_context("Generate playbook related options.",
test.log.info)
extra_vars = {"ansible_ssh_extra_args": ansible_ssh_extra_args,
"ansible_ssh_pass": guest_passwd,
extra_vars = {"ansible_ssh_pass": guest_passwd,
"test_harness_log_dir": test_harness_log_dir}
extra_vars.update(json.loads(ansible_extra_vars))
custom_params = params.object_params("extra_vars")
Expand Down
4 changes: 1 addition & 3 deletions qemu/tests/ansible_with_responsive_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def run(test, params, env):
ansible_callback_plugin = params.get("ansible_callback_plugin")
ansible_connection_plugin = params.get("ansible_connection_plugin")
ansible_addl_opts = params.get("ansible_addl_opts", "")
ansible_ssh_extra_args = params["ansible_ssh_extra_args"]
ansible_extra_vars = params.get("ansible_extra_vars", "{}")
custom_extra_vars = params.objects("custom_extra_vars")
playbook_repo = params["playbook_repo"]
Expand Down Expand Up @@ -67,8 +66,7 @@ def run(test, params, env):

error_context.base_context("Generate playbook related options.",
test.log.info)
extra_vars = {"ansible_ssh_extra_args": ansible_ssh_extra_args,
"ansible_ssh_pass": guest_passwd,
extra_vars = {"ansible_ssh_pass": guest_passwd,
"mq_port": mq_listen_port,
"test_harness_log_dir": test_harness_log_dir}
extra_vars.update(json.loads(ansible_extra_vars))
Expand Down
1 change: 0 additions & 1 deletion qemu/tests/cfg/ansible_test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
toplevel_playbook = "site.yml"
playbook_timeout = 600
ansible_callback_plugin = debug
ansible_ssh_extra_args = "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
ansible_repo = ""
# Here we can define an extra set of variables for the playbook with json format
#ansible_extra_vars = '{"debug_msg": "Hello Ansible!", "force_handlers": true}'
Expand Down
1 change: 0 additions & 1 deletion qemu/tests/cfg/nested_block_resize.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
toplevel_playbook = "site.yml"
playbook_timeout = 600
ansible_callback_plugin = debug
ansible_ssh_extra_args = "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
ansible_repo = ""
only virtio_scsi
wait_response_timeout = 1800
Expand Down
1 change: 0 additions & 1 deletion qemu/tests/cfg/nested_vsock_con_sockets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
virt_test_type = qemu
playbook_timeout = 600
ansible_callback_plugin = debug
ansible_ssh_extra_args = "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
wait_response_timeout = 600
vsocks = vhost_vsock0
vsock_port = 2345
Expand Down
4 changes: 1 addition & 3 deletions qemu/tests/nested_block_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def _on_status(obj, msg):
ansible_callback_plugin = params.get("ansible_callback_plugin")
ansible_connection_plugin = params.get("ansible_connection_plugin")
ansible_addl_opts = params.get("ansible_addl_opts", "")
ansible_ssh_extra_args = params["ansible_ssh_extra_args"]
ansible_extra_vars = params.get("ansible_extra_vars", "{}")
playbook_repo = params["playbook_repo"]
playbook_timeout = params.get_numeric("playbook_timeout")
Expand All @@ -98,8 +97,7 @@ def _on_status(obj, msg):

error_context.base_context("Generate playbook related options.",
test.log.info)
extra_vars = {"ansible_ssh_extra_args": ansible_ssh_extra_args,
"ansible_ssh_pass": guest_passwd,
extra_vars = {"ansible_ssh_pass": guest_passwd,
"mq_port": mq_listen_port,
"test_harness_log_dir": test_harness_log_dir}
extra_vars.update(json.loads(ansible_extra_vars))
Expand Down
4 changes: 1 addition & 3 deletions qemu/tests/nested_vsock_con_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def _send_file_from_host_to_l1(obj, msg):
ansible_callback_plugin = params.get("ansible_callback_plugin")
ansible_connection_plugin = params.get("ansible_connection_plugin")
ansible_addl_opts = params.get("ansible_addl_opts", "")
ansible_ssh_extra_args = params["ansible_ssh_extra_args"]
ansible_extra_vars = params.get("ansible_extra_vars", "{}")
playbook_repo = params["playbook_repo"]
playbook_timeout = params.get_numeric("playbook_timeout")
Expand All @@ -97,8 +96,7 @@ def _send_file_from_host_to_l1(obj, msg):

error_context.base_context("Generate playbook related options.",
test.log.info)
extra_vars = {"ansible_ssh_extra_args": ansible_ssh_extra_args,
"ansible_ssh_pass": guest_passwd,
extra_vars = {"ansible_ssh_pass": guest_passwd,
"mq_port": mq_port,
"test_harness_log_dir": test_harness_log_dir}
extra_vars.update(json.loads(ansible_extra_vars))
Expand Down

0 comments on commit 58f91a6

Please sign in to comment.