babyachievement / notes

读书笔记
1 stars 1 forks source link

OpenStack学习1-ansible安装和使用 #6

Open babyachievement opened 8 years ago

babyachievement commented 8 years ago

安装环境 Ubuntu 14.04 X64

1.安装

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

2.配置和使用

编辑/etc/ansible/hosts文件,该文件中主要保存将要管理的远程系统的信息 例如:

192.168.1.50
aserver.example.org
bserver.example.org

配置SSH免输入密码

$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa

尝试与所有节点进行ping

$ ansible all -m ping

如果想使用sudo模式,可以通过以下方式访问:

# as bruce
$ ansible all -m ping -u bruce
# as bruce, sudoing to root
$ ansible all -m ping -u bruce --sudo
# as bruce, sudoing to batman
$ ansible all -m ping -u bruce --sudo --sudo-user batman

# With latest version of ansible `sudo` is deprecated so use become
# as bruce, sudoing to root
$ ansible all -m ping -u bruce -b
# as bruce, sudoing to batman
$ ansible all -m ping -u bruce -b --become-user batman

通过ansible在所有主机上执行命令

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

[1] http://docs.ansible.com/ansible/intro_installation.html