[root@localmesos ansible_test]# ansible all -a "/bin/echo hello"
192.168.111.111 | SUCCESS | rc=0 >>
hello
--------------------------------------------------------------------------------------------------------------------------------
vi /etc/ansible/hosts
[webservers]
192.168.111.111
[root@localmesos ansible_test]# vi playbook.yml
---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure docker is running (and enable it at boot)
service: name=docker state=started enabled=yes
[root@localmesos ansible_test]# ansible-playbook playbook.yml
PLAY [webservers] ************************************************************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************************************************************
ok: [192.168.111.111]
TASK [ensure docker is running (and enable it at boot)] **********************************************************************************************************************************
changed: [192.168.111.111]
PLAY RECAP *******************************************************************************************************************************************************************************
192.168.111.111 : ok=2 changed=1 unreachable=0 failed=0
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[root@localmesos ansible_test]# vi playbook3.yml
---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: add docker container
add_host:
name: server
ansible_connection: docker
ansible_user: root
changed_when: false
- name: create directory for ssh keys
delegate_to: server
file:
path: "/dada"
state: directory
---------------------------------------------------------------------------------
[root@localmesos ansible_test]# vi playbook3.yml
---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: add docker container
add_host:
name: server
ansible_connection: docker
ansible_user: root
changed_when: false
- name: create directory for ssh keys
delegate_to: server
command: rm -rf /test