Ansible

  作者:会飞的zxl

http://getansible.com/chapter1安裝Ansible软件$ # Redhat/CentOS Linux上,Ansible目前放在的epel源中$ # Fedora默认源中包含ansible,直接安装包既可$ sudo yum install epel-release$ sudo yum install ansible -y$ # 生成ssh key$ ssh-keygen$ # 拷贝ssh key到远程主机,ssh的时候就不需要输入密码了$ ssh-

http://getansible.com/chapter1


安裝Ansible软件

$ # Redhat/CentOS Linux上,Ansible目前放在的epel源中

$ # Fedora默认源中包含ansible,直接安装包既可

$ sudo yum install epel-release 

$ sudo yum install ansible -y 

$ # 生成ssh key

$ ssh-keygen

$ # 拷贝ssh key到远程主机,ssh的时候就不需要输入密码了

$ ssh-copy-id remoteuser@remoteserver

$ # ssh的时候不会提示是否保存key

$ ssh-keyscan remote_servers >> ~/.ssh/known_hosts



ansible命令的格式是:


ansible <host-pattern> [options]


检查ansible安装环境


检查所有的远程主机,是否以bruce用户创建了ansible主机可以访问的环境。


$ansible all -m ping -u bruce


执行命令


在所有的远程主机上,以当前bash的同名用户,在远程主机执行“echo bash”


$ansible all -a "/bin/echo hello"


拷贝文件


拷贝文件/etc/host到远程主机(组)web,位置为/tmp/hosts


$ ansible web -m copy -a "src=/etc/hosts dest=/tmp/hosts"


安装包


远程主机(组)web安装yum包acme


$ ansible web -m yum -a "name=acme state=present"


添加用户


$ ansible all -m user -a "name=foo password=<crypted password here>"


下载git包


$ ansible web -m git -a "repo=git://foo.example.org/repo.git dest=/srv/myapp version=HEAD"


启动服务


$ ansible web -m service -a "name=httpd state=started"


并行执行


启动10个并行进行执行重起


$ansible lb -a "/sbin/reboot" -f 10


查看远程主机的全部系统信息!!!


$ ansible all -m setup


有用  |  无用

猜你喜欢