inventories:主机目录,具体每个文件代表每个主机场景,比如开发服务器、测试服务器、线上服务器等
playbooks: ansible playbook目录
Before start, we should set all server as login without password.
just follow command:
ssh-copy-id user@your-server-ip
Then test ping:
ansible -i inventories/test center -u root -m ping
And center server will response with:
[vagrant@localhost ansible]$ ansible -i inventories/test center -u root -m ping
192.168.1.115 | SUCCESS => {
"changed": false,
"ping": "pong"
}
ansible-playbook -i inventories/test -u root playbooks/test/test.yml
Response:
[vagrant@localhost ansible]$ ansible-playbook -i inventories/test -u root playbooks/test/test.yml
PLAY [all] ********************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************
ok: [192.168.1.115]
TASK [test connection] ********************************************************************************************************************************************
ok: [192.168.1.115]
TASK [test a script] **********************************************************************************************************************************************
changed: [192.168.1.115]
PLAY RECAP ********************************************************************************************************************************************************
192.168.1.115 : ok=3 changed=1 unreachable=0 failed=0
[vagrant@localhost ansible]$ ansible-playbook -i inventories/test -u root playbooks/init-centos/init.yml
PLAY [all] ********************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************
ok: [192.168.1.115]
TASK [Init centos server] *****************************************************************************************************************************************
changed: [192.168.1.115]
PLAY RECAP ********************************************************************************************************************************************************
192.168.1.115 : ok=2 changed=1 unreachable=0 failed=0
[vagrant@localhost ansible]$ ansible-playbook -i inventories/test -u root playbooks/docker/docker.yml
PLAY [all] ********************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************
ok: [192.168.1.115]
TASK [Install docker enviroment] **********************************************************************************************************************************
changed: [192.168.1.115]
PLAY RECAP ********************************************************************************************************************************************************
192.168.1.115 : ok=2 changed=1 unreachable=0 failed=0
[vagrant@localhost ansible]$ ansible-playbook -i inventories/test -u root playbooks/openldap/openldap.yml
PLAY [all] ********************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************
ok: [192.168.1.115]
TASK [install openldap] *******************************************************************************************************************************************
changed: [192.168.1.115]
PLAY RECAP ********************************************************************************************************************************************************
192.168.1.115 : ok=2 changed=1 unreachable=0 failed=0