ansible环境搭建

一、实现从管理机m01到其他机器的密钥认证

[root@m01 ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/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:rKu2og75VVHnsOPn/Lh9YP/2Yi26PwD9wAzMihol4e8 root@m01
The key's randomart image is:
+---[RSA 2048]----+
|    ..  oo.      |
|   .. .. =+      |
|    .o..o..=     |
|    ...+... =    |
|     oo S .. o   |
| .  .o . +  + .  |
|o   . E   o. + . |
|.....  .   +  B o|
|oo.ooo.   o.=*.*+|
+----[SHA256]-----+
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub  -p 22 root@172.16.1.7
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.7
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.61

二、安装ansible

[root@m01 ~]# yum install ansible -y

三、配置ansible的主机列表

[root@m01 ~]# vim /etc/ansible/hosts
[server]
172.16.1.61
[client]
172.16.1.7

四、验证ansible

ansible是通过ssh端口探测通信
[root@m01 /etc/ansible]# ansible server -m ping
10.0.0.61 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
[root@m01 /etc/ansible]# ansible client -m ping
10.0.0.7 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
[root@m01 /etc/ansible]# ansible server -m command -a "df -h" 
10.0.0.61 | CHANGED | rc=0 >>
文件系统                           容量  已用  可用 已用% 挂载点
/dev/mapper/centos_oldboyedu-root   17G  3.2G   14G   19% /
devtmpfs                           979M     0  979M    0% /dev
tmpfs                              991M  128K  991M    1% /dev/shm
tmpfs                              991M  9.7M  981M    1% /run
tmpfs                              991M     0  991M    0% /sys/fs/cgroup
/dev/sda1                         1014M  194M  821M   20% /boot
tmpfs                              199M     0  199M    0% /run/user/0
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Ansible配置管理系统 Ansible是一个配置管理系统configuration management sy...
    山有木兮_8adb阅读 1,950评论 0 0
  • 1.ssh-keygen非交互式创建秘钥对: 具体命令:ssh-keygen -f ~/.ssh/id_rsa ...
    1220阅读 4,617评论 0 0
  • Ansible配置管理系统 作者 Michael 在Ansible基础 Ansible配置管理系统Ansible是...
    cf5fffef0d0e阅读 3,544评论 0 0
  • Ansible是一个配置管理系统configuration management system,你只需要可以使用s...
    zwb_jianshu阅读 4,415评论 0 0
  • 目标:八月一日前租到合心的房子。 好种子: 1、制定计划,分享给业力伙伴。她受到提醒也制定了计划,给她提了建议:具...
    Larissa瞬年阅读 1,405评论 0 0

友情链接更多精彩内容