篇幅二. docker安装
(部分相同文件在此篇不列举,可见篇幅一)
1.docker 安装
1.1 tree /home/jenkins/ansible_workspace
/home/jenkins/ansible_workspace/
├── deploy_process.yml
├── environments
│ ├── colony
│ ├── inventory
│ └── vars.yml
├── roles
│ ├── docker_install
│ │ ├── files
│ │ │ └── daemon.json
│ │ ├── meta
│ │ │ └── main.yml
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── templates
│ ├── docker_uninstall
│ └── tasks
│ └── main.yml
└── utils_install.yml
1.2 cat /home/jenkins/ansible_workspace/roles/docker_install/tasks/main.yml
---
- name: judge daemon.json exist
shell: ls /etc/docker/daemon.json> /dev/null
ignore_errors: True
register: daemon_json
- name: install docker ce
shell: yum clean all && yum install -y docker-ce
tags: docker_install
when: daemon_json is failed
- name: create docker setting dir
file: name=/etc/docker state=directory owner=root group=root mode=0755
tags: create_dir
when: daemon_json is failed
- name: cp docker daemon
copy: src=~/ansible_workspace/roles/docker_install/files/daemon.json dest=/etc/docker/daemon.json
tags: cp_config
when: daemon_json is failed
- name: restart docker service
service: name=docker state=restarted enabled=yes daemon_reload=yes
tags: start_service
when: daemon_json is failed
- name: enable docker service
service: name=docker state=started enabled=yes daemon_reload=yes
tags: enable_service
when: daemon_json is failed
1.3 cat /home/jenkins/ansible_workspace/roles/docker_install/files/daemon.json
{
"insecure-registries": ["1.1.1.1:5000"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"data-root": "/home/docker/app",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
1.4 cat /home/jenkins/ansible_workspace/roles/docker_install/meta/main.yml
---
dependencies:
- role: yum_client_install
1.5 jenkins job参数
1.5 jenkins job shell 构建内容
ansibleHome='/home/jenkins/ansible_workspace'
cd ${ansibleHome}
ansible-playbook utils_install.yml -i environments/${environment}/inventory -e "hosts=${hosts} user_name=${user_name} env=${environment} ansibleHome=${ansibleHome} util=docker_install"