首页 > 其他分享 >Ansible-受控主机配置并测试连通性

Ansible-受控主机配置并测试连通性

时间:2023-05-05 14:22:37浏览次数:46  
标签:受控 连通性 ansible 192.168 Ansible ssh key root id

1.Ansible配置文件

[root@master home]# ansible --version
ansible 2.9.27
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

2.Ansible配置受控主机

vi /etc/ansible/hosts

 3.利用ping 模块,检测与目标主机的连通性

[root@master home]# ansible 192.168.142.36 -m ping
192.168.142.36 | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", 
    "unreachable": true
}

原因:没有在ansible管理节点(即安装ansible的节点)上添加目标节点(即需要管理的节点)的ssh认证信息。

解决步骤:

1:管理节点生成SSH-KEY

[root@master home]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:BqRfboDSZGdidf8tpmpgSIHcYmS8lT50QrJ/lWQYOaw root@master
The key's randomart image is:
+---[RSA 2048]----+
| +++*+*++        |
| .*BBB*+ o       |
| .o*+=o.+ .      |
|  .oE. *   . .   |
|   ..oo S   + .  |
|    ..oo   o .   |
|     . .  .      |
|        ..       |
|       ..        |
+----[SHA256]-----+

成功后在~/.ssh/路径下将生成ssh密钥文件:id_rsa及id_rsa.pub

2:添加目标节点的SSH认证信息

#ssh-copy-id root@目标节点IP

[root@master home]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@master home]# ansible 192.168.142.36 -m ping
192.168.142.36 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
[root@master home]# ansible -m ping all
192.168.142.36 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

 

标签:受控,连通性,ansible,192.168,Ansible,ssh,key,root,id
From: https://www.cnblogs.com/joyware/p/17373996.html

相关文章

  • Ansible-安装
    第一步:安装我们的epel扩展源yum-yinstallepel-release我这里会报/var/run/yum.pid已被锁定,如果没有直接进行下一步[root@masterhome]#yum-yinstallepel-release已加载插件:fastestmirror,langpacks/var/run/yum.pid已被锁定,PID为22410的另一个程序正在运行。......
  • ansible基础使用
    简述ansible是新出现的自动化运维工具,基于Python开发集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点实现了批量系统配置、批量程序部署、批量运行命令等功能,无客户端ansible是基于paramiko开发的,并且基于模块化工作,本身没有批量部署的能力。真正具有批量......
  • 自动化运维工具Ansible
    一、ansible是什么?ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于paramiko开发的,并且基于模块化工作,本身没有批量部署的能力。真正具有批......
  • Ansible之playbook剧本
    1.playbook的组成playbooks本身由以下各部分组成(1)Tasks:任务,即通过task调用ansible的模板将多个操作组织在一个playbook中运行(2)Variables:变量(3)Templates:模板(4)Handlers:处理器,当changed状态条件满足时,(notify)触发执行的操作(5)Roles:角色2.剧本示例test12.1剧本制作 [......
  • Ansible之playbook剧本
    一、playbook1.什么是playbookplaybook是ansible用于配置,部署,和管理被控节点的剧本。通过playbook的详细描述,执行其中的tasks,可以让远端主机达到预期的状态。playbook是由一个或多个”play”组成的列表。当对一台机器做环境初始化的时候往往需要不止做一件事情,这时使用playboo......
  • 将ansible的输出转换为JSON格式
    第一步找到ansible.cfg我的ansible.cfg的文件在/etc/ansible文件夹的下面。可以使用Linux命令行进行切换到这个文件夹下面。cd/etc/ansible第二步,修改ansible.cfg文件,在配置文件中添加以下的配置。[defaults]stdout_callback=jsonbin_ansible_callbacks=True ......
  • Ansible快速入门
    Ansible快速入门1.1什么是AnsibleAnsible是一个IT自动化的配置管理工具,自动化主要体现在:Ansible集成了丰富模块,以及强大的功能组件,可以通过一个命令行完成一系列的操作。进而能减少我们重复性的工作,以提高工作的效率。1.2Ansible主要功能批量执行远程命令,可以对N多台主机......
  • ansible 第一次批量导入ssh-key
    适用环境:所有主机具有相同的用户名和密码实现方式:通过ansiblehosts文件读取主机列表通过expect自动应答脚本出处:githubkubeasz\tools#!/bin/bash#此脚本为批量部署服务器sshkey使用#set-x#checkargscountiftest$#-ne3;thenecho-e"\nUsag......
  • 71、ansible编排-playbook
    playbook介绍在Ansible中,Playbook是一个用YAML格式编写的文本文件,它描述了一系列任务,每个任务又是一个或多个action的集合。Playbook通过在远程主机上执行任务来实现自动化。在playbook中,可以指定主机、变量、任务、处理器、模块等等。通过对这些组件的组合和配置,可以实......
  • ansible推送文件到目标主机时报错 UNREACHABLE! | Permission denied (publickey,gssa
    问题现象:[root@linlin]#ansibleall-mcopy-a'src=/etc/ansible/lin/test.txtdest=/home/'192.168.12.203|UNREACHABLE!=>{"changed":false,"msg":"Failedtoconnecttothehostviassh:[email protected]:Pe......