This ansible playbook will helpful to install docker swarm cluster setup and monitoring metrics components like node-exporter and cadvisor.
Source : https://github.com/JREXANDREW/ansible-docker-metrics
Usage in Jenkins
Create a Jenkings Job for each playbook and configure the playbook.
Playbook for Install Docker Swarmm Cluster - king_install_docker.yml
Playbook for Install Metrics Components(node-exporter,cadvisor) - king_metrics.yml
We will also use Tag in Jenkinks Job parameter.
ANSIBLE_TAGS
deploy - when this parameter is passed to ANSIBLE_TAGS in "Build with Parameters, this will run only the deploy role
undeploy - when this parameter is passed to ANSIBLE_TAGS in "Build with Parameters, this will run only the undeploy role
verify - when this parameter is passed to ANSIBLE_TAGS in "Build with Parameters, this will run only the verify role
Sample playbook for install docker and its components
---
- name: Check if Docker is installed
command: systemctl status docker
register: docker_check
ignore_errors: yes
- name: Install yum utils
yum:
name: yum-utils
state: latest
when: docker_check.stderr.find('service could not be found') != -1
- name: Add Docker repo
get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: /etc/yum.repos.d/docer-ce.repo
when: docker_check.stderr.find('service could not be found') != -1
- name: Install Docker
package:
name: docker-ce
state: latest
when: docker_check.stderr.find('service could not be found') != -1
- name: Install Docker cli
package:
name: docker-ce-cli
state: latest
when: docker_check.stderr.find('service could not be found') != -1
- name: Install Docker containerd
package:
name: containerd.io
state: latest
when: docker_check.stderr.find('service could not be found') != -1
- name: Enable the Docker daemon in systemd
systemd:
name: docker
enabled: yes
masked: no
when: docker_check.stderr.find('service could not be found') != -1
- name: Start the Docker daemon
systemd:
name: docker
state: started
masked: no
when: docker_check.stderr.find('service could not be found') != -1
- name: Docker Login gcr.io
shell: docker login -u _json_key -p "$(cat /usr/src/gcr.json)" https://gcr.io
Comments