## 安裝
~~~
yum install -y ansible
~~~
在centos7上會安裝以下依賴
~~~
PyYAML
libtomcrypt
libtommath
libyaml
python-babel
python-backports
python-backports-ssl_match_hostname
python-httplib2
python-jinja2
python-keyczar
python-markupsafe
python-setuptools
python-six
python2-crypto
python2-ecdsa
python2-paramiko
python2-pyasn1
sshpass
~~~
## 認證
### 生成密鑰
~~~
ssh-keygen -t rsa
# 或者,免輸入密碼和私鑰文件路徑
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
~~~
### 復制密鑰到客戶機
~~~
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.101.175
~~~
### 認證測試
登錄成功即密鑰測試通過
~~~
ssh node2.test.com
~~~
或者將主機加入ansible的hosts后,使用ping模塊進行測試
~~~
ansible test -m ping
192.168.101.175 | SUCCESS => {
"changed": false,
"ping": "pong"
}
~~~
### 查看文檔
~~~
ansible-doc -l 列出所有模塊
ansible-doc -s 列出某一模塊的幫助
~~~
### ansible命令格式
~~~
ansible <host-pattern> [-m module_name] [-a args] [options]
-C, --check # 只是測試將會執行的操作,不進行任何實質性的操作
-f, --forks=NUM # 并發數
-i, --inventory=PATH # 主機列表文件
-T, --timeout=SECONDS # 超時時間
~~~
>[info] all 代表所有在主機列表中的主機
- 目錄
- ansible基礎
- ansible簡介
- ansible安裝和測試
- ansible配置文件
- 常用命令
- yaml在ansible中的用法
- inventory
- 變量與facts
- when語句
- handler模塊
- 大雜燴
- ansible模塊
- assert 模塊
- copy模塊
- cron模塊
- debug模塊
- django_manage模塊
- file模塊
- filesystem模塊
- git模塊
- hostname模塊
- lineinfile模塊
- mount模塊
- mysql_user模塊
- mysql_db模塊
- pip模塊
- selinux
- setup模塊
- shell 和 command 模塊
- stat模塊
- supervisorctl
- systemd
- timezone
- unarchive模塊
- user模塊
- wait_for
- yum和service模塊
- 其他模塊或者方法
- setup模塊
- url模塊
- slack 模塊
- pause 模塊
- 其他
- 報錯處理
- playbooks
- 復雜的playbook
- 循環
- roles
- YAML
- jinja2