ansible实例

2020-10-20

ansible通过ssh无密码访问,可以批量部署一些东西。

 

1、https://www.ansible.com/

2、yum安装:

#!/bin/sh

dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf -y install ansible
ansible --version

3、编辑/etc/ansible/hosts

[webserver]
172.16.11.[242:251]
172.16.10.[4:13]

4、批量执行命令ansible -m command -a "df -h" "webserver"

5、copy文件到另一个目录

ansible webserver -m copy -a "src=/etc/hosts dest=/opt/"

6、ansible -m shell -a "cat /opt/scripts/my-hosts >> /etc/hosts" "webserver"

7、ansible webserver -m yum -a "name=lrzsz"

8、ansible webserver -m service -a "name=httpd state=restarted"

分类:Linux | 标签: |

相关日志

评论被关闭!