- Jenkins server
- Docker-host server
- Ansible server
Dockerfile
under/opt/docker
on Ansible server Get Help Here# Pull tomcat latest image from dockerhub From tomcat # Maintainer MAINTAINER "AR Shankar" # copy war file on to container COPY ./webapp.war /usr/local/tomcat/webapps
- Create
create-docker-image.yml
unser/opt/docker
on Ansible server Get Help Here--- - hosts: all #ansadmin doesn't need root access to create an image become: true tasks: - name: building docker image command: "docker build -t simple-devops-image ." args: chdir: /opt/docker
- Create
create-docker-image.yml
under/opt/docker
on Ansible server Get Help Here--- - hosts: all become: ture tasks: - name: creating docker image using docker command command: docker run -d --name simple-devops-container -p 8080:8080 simple-devops-image
Install "publish Over SSH"
Manage Jenkins
>Manage Plugins
>Available
>Publish over SSH
Enable connection between Ansible-control-node and Jenkins
-
Manage Jenkins
>Configure System
>Publish Over SSH
>SSH Servers
- SSH Servers:
- Name:
ansible-server
-
Hostname:
<ServerIP>
-
username:
ansadmin
-
Advanced
> choseUse password authentication, or use a different key
-
password:
*******
-
- SSH Servers:
- Name:
-
Enter an item name:
Deploy_on_Container_using_ansible
- Copy from:
Deploy_on_Container
- Copy from:
-
Source Code Management:
- Repository:
https://github.com/yankils/hello-world.git
- Branches to build :
*/master
- Repository:
-
Poll SCM : -
* * * *
-
Build:
- Root POM:
pom.xml
- Goals and options:
clean install package
- Root POM:
-
Post-build Actions
- Send build artifacts over SSH
- SSH Publishers
- SSH Server Name:
ansible-server
Transfers
>Transfer set
- Source files:
webapp/target/*.war
- Remove prefix:
webapp/target
- Remote directory:
//opt//docker
- Exec command:
ansible-playbook -i /opt/docker/hosts /opt/docker/create-docker-image.yml;
- Source files:
- Send build artifacts over SSH
Save and run the job now.