Ansible 简单上手
Ansible 有很多专业的配置,但是如下简单几步就可以让你先玩起来了 ~_~
安装:
# yum install ansible
服务器免密认证:
如果对方直接有 authorized_keys 文件,则直接添加 key 内容 。 # ssh root@192.168.1.101 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub 如果对方机器没有,就要先建立 .ssh 目录及 authorized_keys 文件,然后再添加 key 内容 。 # ssh root@192.168.1.101 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
增加群组:
# vim /etc/ansible/hosts [test] 172.168.1.101 172.168.1.102 172.168.1.103 172.168.1.104 172.168.1.105 172.168.1.106
PING:
# ansible "test" -m ping
执行命令:
# ansible "test" -m shell -a "ls -l /usr/local/src/"
启动服务:(started/stopped/restarted)
# ansible "172.16.1.101" -m service -a "name=zabbix-agent state=started"
拷贝文件:
# ansible "test" -m copy -a "src=/usr/local/src/ansible_test.txt dest=/usr/local/src/ansible_test.txt"
查看机器信息:
# ansible "test" -m setup
[ TO BE CONTINUE ]