ansible安装配置记录


1、控制节点yum安装epel-release 和 ansible
[root@localhost ~]# yum install epel-release -y 
[root@localhost ~]# yum install ansible -y
[root@localhost ~]# ansible 
[root@localhost ~]# cd /etc/ansible/
[root@localhost ~]# vim  ansible.cfg 
【根据实际情况配置参数】
inventory      = /etc/ansible/hosts
library        = /usr/share/my_modules/
forks          = 5
sudo_user      = root
remote_port    = 22
host_key_checking = False
timeout = 60
log_path = /var/log/ansible.log
2、配置被控制节点
[root@localhost ~]# vim  hosts
[web]
192.168.193.20
192.168.193.22
(这里添加一个web组,下有两台服务器)

3、配置公私钥,用加密方式生成公钥
[root@localhost ~]# ssh-keygen   -t  rsa
【一直回车到结束】

向被控制节点192.168.193.20分发私钥
[root@localhost ~]# ssh-copy-id   root@192.168.193.20
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.193.20 (192.168.193.20)' can't be established.
ECDSA key fingerprint is SHA256:+iFwpdLBAirR98HIl0BaE4S85siezj4PZwJecotxRUs.
ECDSA key fingerprint is MD5:85:81:b3:4e:e9:07:c8:2b:9f:06:99:8c:95:86:65:79.
Are you sure you want to continue connecting (yes/no)? yes
/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
root@192.168.193.20's password: 【输入控制节点root密码】

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.193.20'"
and check to make sure that only the key(s) you wanted were added.
[root@localhost ~]#

向被控制节点192.168.193.22分发私钥
[root@localhost ~]# ssh-copy-id   root@192.168.193.22
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.193.22 (192.168.193.22)' can't be established.
ECDSA key fingerprint is SHA256:PtXL4y7BbOiWL9kUzVaPrVEf855pyDFgYZhAIxddRck.
ECDSA key fingerprint is MD5:94:f7:12:77:7d:b4:89:c4:e0:fd:a7:22:22:35:f9:b6.
Are you sure you want to continue connecting (yes/no)? yes
/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
root@192.168.193.22's password: 【输入控制节点root密码】

Number of key(s) added: 1

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

[root@localhost ~]#

4、测试验证ansible命令
[root@localhost ~]# ansible  "web" --list
  hosts (2):
    192.168.193.20
    192.168.193.22
[root@localhost ~]# time  ansible web -m  ping
192.168.193.22 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
192.168.193.20 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

real    0m1.037s
user    0m0.502s
sys    0m0.321s
【ansible前面加time可以显示出命令执行时间】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值