ssh首次链接出现yes/no提示和ansible提示

修改文件: /etc/ssh/ssh_config 

在文件中添加如下信息:StrictHostKeyChecking no

改本机的/etc/ssh/ssh_config文件中的"# StrictHostKeyChecking ask" 为 "StrictHostKeyChecking no",

 

 

如何去除ssh无交互式添加 known_hosts

 

配置文件/etc/ansible/ansible.cfg的[defaults]中

 

打开注释

 

# uncomment this to disable SSH key host checking

 

host_key_checking = False

 

ansible自动下发ssh密钥:

https://docs.ansible.com/ansible/latest/modules/authorized_key_module.html

- name: Set authorized key taken from file
  authorized_key: user: charlie state: present key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}" - name: Set authorized keys taken from url authorized_key: user: charlie state: present key: https://github.com/charlie.keys - name: Set authorized key in alternate location authorized_key: user: charlie state: present key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}" path: /etc/ssh/authorized_keys/charlie manage_dir: False - name: Set up multiple authorized keys authorized_key: user: deploy state: present key: '{{ item }}' with_file: - public_keys/doe-jane - public_keys/doe-john - name: Set authorized key defining key options authorized_key: user: charlie state: present key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}" key_options: 'no-port-forwarding,from="10.0.1.1"' - name: Set authorized key without validating the TLS/SSL certificates authorized_key: user: charlie state: present key: https://github.com/user.keys validate_certs: False - name: Set authorized key, removing all the authorized keys already set authorized_key: user: root key: '{{ item }}' state: present exclusive: True with_file: - public_keys/doe-jane - name: Set authorized key for user ubuntu copying it from current user authorized_key: user: ubuntu state: present key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"

 

转载于:https://www.cnblogs.com/smlie/p/10994755.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 Ansible 配置文件模板 /etc/ansible/ansible.cfg: ``` [defaults] # inventory 文件的位置 inventory = /etc/ansible/hosts # SSH 连接超时时间 timeout = 10 # 任务执行的最大并发数 forks = 5 # 日志文件的位置 log_path = /var/log/ansible.log # 指定 SSH 用户名 remote_user = ansible # 指定 SSH 私钥文件的位置 private_key_file = /root/.ssh/id_rsa # 忽略 SSH 主机密钥检查 host_key_checking = False # 指定 Ansible 模块的路径 module_path = /usr/share/ansible/modules # 指定 Ansible 角色的路径 roles_path = /etc/ansible/roles # 是否启用 Ansible 加速模式 accelerate = False # 加速模式的传输类型 accelerate_port = 5099 accelerate_connect_timeout = 10 accelerate_daemon_timeout = 30 accelerate_multi_key = yes # 设置 Ansible 的本地路径 local_tmp = $HOME/.ansible/tmp remote_tmp = /tmp # 是否启用 Ansible 事务 # 如果启用,Ansible 将在执行每个任务之前检查目标主机的状态 # 如果检查失败,任务将被终止并回滚 # 如果禁用,Ansible 会尽力执行每个任务 # 但是,如果某个任务失败,可能会导致系统处于不一致状态 # 所以建议启用事务模式 # 默认是启用 ansible_check_mode = False # 是否启用 Ansible Facts # Facts 是 Ansible 内置的模块,可以收集目标主机的系统信息 # 如果启用,Ansible 将在每次执行任务之前收集 Facts # 如果禁用,Ansible 不会收集 Facts # 默认是启用 gather_facts = True # 指定 Ansible 的远程执行器 # 有三种可选的执行器:ssh、paramiko、local # 默认是 ssh 执行器 # 如果你的目标主机无法使用 SSH,可以考虑使用 paramiko 执行器 # 如果你使用 Ansible 进行本地开发或测试,可以使用 local 执行器 #remote_port = 22 #remote_tmp = $HOME/.ansible/tmp #remote_user = root #ansible_connection = ssh #ansible_ssh_pass = password #ansible_ssh_private_key_file = /path/to/key #ansible_ssh_common_args = -o StrictHostKeyChecking=no #ansible_python_interpreter=/usr/bin/python3 #ansible_winrm_transport=ntlm #ansible_winrm_server_cert_validation=ignore #ansible_winrm_scheme=http #ansible_winrm_port=5985 #ansible_winrm_user=Administrator #ansible_winrm_password=Password123 #ansible_winrm_transport=ssl # 指定 Ansible 的默认模块参数 # 这个选项可以用于指定 Ansible 模块的默认参数 # 如果模块需要额外的参数,可以在 playbook 中指定 # 如果不需要额外的参数,可以使用这个选项简化 playbook 的编写 # 如果模块本身已经有默认参数,那么 playbook 中指定的参数会覆盖默认参数 #module_name = command #module_args = /bin/true ``` 这只是一个简单的示例,你可以根据你的需要调整 Ansible 的配置文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值