ansible

 

ansible 

 

 

 

MrNeo  Chan陈景峰(BG7NYT)

 

文档尚未完成,请勿转载!

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

ansible
文档出处:
http://netkiller.sourceforge.net
http://netkiller.github.com

 

$Date: 2012-04-17 18:49:40 +0800 (Tue, 17 Apr 2012) $

 

 

1. ansible

http://ansible.github.com/

Ansible is a radically simple model-driven configuration management, deployment, and command execution framework.

1.1. install

yum install ansible
			

1.2. Getting Started

Your first commands

/etc/ansible/hosts

# vim /etc/ansible/hosts

192.168.2.10
192.168.2.11
192.168.2.12
192.168.2.13
192.168.2.14
192.168.2.15
			

创建SSH公钥与私钥

ssh-keygen
			

将公钥文件复制到目标服务器

ssh-copy-id [email protected]
ssh-copy-id [email protected]
ssh-copy-id [email protected]
ssh-copy-id [email protected]
ssh-copy-id [email protected]
ssh-copy-id [email protected]
			

连接与验证测试 ansible all -m ping

# ansible all -m ping
192.168.2.10 | success >> {
    "module": "ping",
    "ping": "pong"
}

192.168.2.13 | success >> {
    "module": "ping",
    "ping": "pong"
}

192.168.2.14 | success >> {
    "module": "ping",
    "ping": "pong"
}

192.168.2.11 | success >> {
    "module": "ping",
    "ping": "pong"
}

192.168.2.15 | success >> {
    "module": "ping",
    "ping": "pong"
}

192.168.2.12 | success >> {
    "module": "ping",
    "ping": "pong"
}
			

1.3. ansible - run a command somewhere else

指定用户

# ansible all -m ping -u root

 

 

1.3. ansible - run a command somewhere else

指定用户

# ansible all -m ping -u root
			

1.4. ansible-playbook - run an ansible playbook

定义组

# cat /etc/ansible/hosts
[www]
192.168.2.23
			

创建yml文件

# cat test.yml
---
- hosts: www
  user: root
  tasks:
  - name: no selinux
    action: command /usr/sbin/setenforce 0

  - name: no iptables
    action: service name=iptables state=stopped

  - name: made up task just to show variables work here
    action: command /bin/echo release is $release
			

执行任务

# ansible-playbook test.yml -u root -T 1

PLAY [www] *********************

GATHERING FACTS *********************
ok: [192.168.2.23]

TASK: [no selinux] *********************
ok: [192.168.2.23]

TASK: [no iptables] *********************
ok: [192.168.2.23]

TASK: [made up task just to show variables work here] *********************
ok: [192.168.2.23]

PLAY RECAP *********************
192.168.2.23                   : ok=4    changed=2    unreachable=0    failed=0

 

 

你可能感兴趣的:(linux,centos,Debian,netkiller,ansible)