ansible部署配置

版权声明:Don't trouble trouble until trouble troubles you. https://blog.csdn.net/JOJOY_tester/article/details/86022888

安装ansible

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

配置ansible

[root@centos7 ~]# ll /etc/ansible/

总用量 24

-rw-r--r-- 1 root root 20277 12月 4 01:07 ansible.cfg   #ansible的配置文件

-rw-r--r-- 1 root root 1016 12月 4 01:07 hosts             #用来配置被管理的机器

drwxr-xr-x 2 root root 6 12月 4 01:07 roles                 # 一个目录,playbook将使用它

1.ansible管理机器和被管理机器做密匙连接

[root@centos7 roles]# ssh-keygen # 生成密匙 

[root@centos7 .ssh]# /usr/bin/ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.0.102 # 将管理机器的公钥写进被管理机器

2.hosts文件添加被管理机器

[root@centos7 ansible]# cp hosts hosts_bak

[root@centos7 ansible]# > hosts

[root@centos7 ansible]# vim /etc/ansible/hosts

[client]

192.168.0.102

测试ansible 

[root@centos7 ansible]# ansible Client -m ping # 操作主机文件中Client组,(all 是操作hosts文件中所有主机),-m执行执行ping模块

下面是返回结果:

# -i 指定 hosts 文件位置

# -u username 指定 SSH 连接的用户名

# -k 指定远程用户密码

# -f 指定并发数

# -s 如需要 root 权限执行时使用 ( 连接用户不是 root 时 )

# -K -s 时,-K 输入 root 密码

猜你喜欢

转载自blog.csdn.net/JOJOY_tester/article/details/86022888