ansible自动化工具安装和简单使用

ansible自动化工具安装和简单使用

1.安装

ansible依赖于Python 2.6或更高的版本、paramiko、PyYAML及Jinja2。

2.1 编译安装

解决依赖关系

# yum -y install python-jinja2 PyYAML python-paramiko python-babel python-crypto

# yum install ansible

在node1(Master):
# ssh-keygen -t rsa   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2    
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3    
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node5
在node2 (slave):
# ssh-keygen -t rsa   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node1    
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3    
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node5

常用命令:
ping 主机
ansible web -a 'ping'
查看磁盘挂载
ansible web -a 'df -h'


远程传送文件
ansible web -m copy -a "src=/root/1.txt dest=/root/"
修改文件
ansible web -m lineinfile -a 'path=/root/1.txt regexp="^12334" line="test text" '

猜你喜欢

转载自www.cnblogs.com/zoulixiang/p/9395370.html