create inventry


In [3]:
%%writefile inventory
[servers]
192.168.33.10


Overwriting inventory

In [4]:
cat inventory


[servers]
192.168.33.10

create ansible-playbook

ansible-playbook-install-apache2.yml


In [5]:
%%writefile ansible-playbook-install-apache2.yml
---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: install apache2
    apt: name=apache2 state=present update_cache=yes
  - name: start apache2
    service: name=apache2 state=restarted


Writing ansible-playbook-install-apache2.yml

In [6]:
cat ansible-playbook-install-apache2.yml


---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: install apache2
    apt: name=apache2 state=present update_cache=yes
  - name: start apache2
    service: name=apache2 state=restarted

ansible-playbook-uninstall-apache2.yml


In [6]:
%%writefile ansible-playbook-uninstall-apache2.yml
---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: stop apache2
    service: name=apache2 state=stopped
  - name: uninstall apache2
    apt: name=apache2 state=absent


Overwriting ansible-playbook-uninstall-apache2.yml

In [7]:
cat ansible-playbook-uninstall-apache2.yml


---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: stop apache2
    service: name=apache2 state=stopped
  - name: uninstall apache2
    apt: name=apache2 state=absent

ansible-playbook-install-docker.yml


In [7]:
%%writefile ansible-playbook-install-docker.yml
---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: install wget
    apt: name=wget state=present update_cache=yes
  - name: install docker
    shell: wget -qO- https://get.docker.com/ | sh
  - name: start docker
    service: name=docker state=restarted


Overwriting ansible-playbook-install-docker.yml

In [8]:
cat ansible-playbook-install-docker.yml


---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: install wget
    apt: name=wget state=present update_cache=yes
  - name: install docker
    shell: wget -qO- https://get.docker.com/ | sh
  - name: start docker
    service: name=docker state=restarted

ansible-playbook-install-td-agent2.yml


In [9]:
%%writefile ansible-playbook-install-td-agent2.yml
---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: install curl
    apt: name=curl state=present update_cache=yes
  - name: install td-agent2
    shell: curl -L http://toolbelt.treasuredata.com/sh/install-ubuntu-trusty-td-agent2.sh | sh
  - name: start td-agent
    service: name=td-agent state=started


Overwriting ansible-playbook-install-td-agent2.yml

In [10]:
cat ansible-playbook-install-td-agent2.yml


---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: install curl
    apt: name=curl state=present update_cache=yes
  - name: install td-agent2
    shell: curl -L http://toolbelt.treasuredata.com/sh/install-ubuntu-trusty-td-agent2.sh | sh
  - name: start td-agent
    service: name=td-agent state=started

ansible-playbook-install-td-agent-plugin.yml

td-agent.conf


In [11]:
%%writefile td-agent.conf
<source>
type docker_metrics
# stats_interval 1m
stats_interval 10s
# cgroup_path /sys/fs/cgroup
# tag_prefix docker
# docker_socket unix:///var/run/docker.sock
# docker_network_path /sys/class/net
# docker_infos_path /var/lib/docker/execdriver/native
</source>
 
<match **>
type stdout
</match>


Overwriting td-agent.conf

In [12]:
cat td-agent.conf


<source>
type docker_metrics
# stats_interval 1m
stats_interval 10s
# cgroup_path /sys/fs/cgroup
# tag_prefix docker
# docker_socket unix:///var/run/docker.sock
# docker_network_path /sys/class/net
# docker_infos_path /var/lib/docker/execdriver/native
</source>
 
<match **>
type stdout
</match> 

td-agent-plugin


In [13]:
%%writefile ansible-playbook-install-td-agent-plugin.yml
---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: install plugin
    shell: /usr/sbin/td-agent-gem install fluent-plugin-docker-metrics
  - name: copy td-agent.conf
    copy: src=td-agent.conf dest=/etc/td-agent/td-agent.conf force=yes
    notify:
     - restart td-agent
  - name: td-agent user add to docker
    shell: gpasswd -a td-agent docker
  - name: restart td-agent
    service: name=td-agent state=restarted


Overwriting ansible-playbook-install-td-agent-plugin.yml

In [14]:
cat ansible-playbook-install-td-agent-plugin.yml


---
- hosts: 192.168.33.10
  user: vagrant
  sudo: yes
  tasks:
  - name: install plugin
    shell: /usr/sbin/td-agent-gem install fluent-plugin-docker-metrics
  - name: copy td-agent.conf
    copy: src=td-agent.conf dest=/etc/td-agent/td-agent.conf force=yes
    notify:
     - restart td-agent
  - name: td-agent user add to docker
    shell: gpasswd -a td-agent docker
  - name: restart td-agent
    service: name=td-agent state=restarted

In [ ]: