Ansible安装

来源:互联网 发布:资管新规 知乎 编辑:程序博客网 时间:2024/05/23 13:04

简介:
Ansible提供两种方式去完成任务,一是 ad-hoc 命令,一是写 Ansible playbook.前者可以解决一些简单的任务, 后者解决较复杂的任务.(类似于在命令行敲入shell命令和 写shell scripts两者之间的关系)…
1.安装

[root@localhost ~]# git clone git://github.com/ansible/ansible.git --recursive[root@localhost ~]# cd ansible/[root@localhost ~]# cd hacking/[root@localhost ~]# source ./env-setup[root@localhost ~]# ansible --version

2.编辑hosts文件,默认没有这个文件,自己创建

[root@localhost ~]# vim /etc/ansible/hosts[test]172.16.0.112

3.配置ssh无密码登录

[root@localhost ~]# ssh-keygen[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.168.0.112

4.尝试几条操作

[root@localhost ~]# ansible all -m ping[root@localhost ~]# ansible constrol -m command -a 'date'[root@localhost ~]# ansible all -a "/bin/echo hello"[root@localhost ~]# ansible test -a "/usr/bin/python" -u root[root@localhost ~]# ansible test -m shell -a "echo $TERM" [root@localhost ~]# ansible 172.16.0.112 -m copy -a “src=/etc/hosts dest=/tmp/hosts"[root@localhost ~]# ansible 172.16.0.112 -m file -a "dest=/tmp/hosts mode=777"

参考链接:
http://www.ansible.com.cn/index.html

原创粉丝点击