Note: First prepare jenkins server how to build jenkins
Since the last article jenkins is adopted and deployed in the war in tomcat to complete the installation, so here Introducing user tomcat start at: tomcat , the following will be used, the article start tomcat user tomcat jar and are used, attention jenkins user and the target server to be consistent, otherwise ansible push and call the jar when unexpected problems may occur; detailed contents will be built in the next section to illustrate the job.
Installation ansible
I use the system comes with python version
Also free to upgrade python version
This article is not focused introduces ansible, although there are many online ansible installation, but this is the most simple way to install
yum -y install ansible
After installation is complete, enter a command to view the installation
[tomcat@RZ-DEV-COM-XZSX-JENKINS-01 xzsx-micro-parent]$ python --version Python 2.7.5 [tomcat@RZ-DEV-COM-XZSX-JENKINS-01 xzsx-micro-parent]$ ansible --version ansible 2.4.2.0 config file = /etc/ansible/ansible.cfg configured module search path = [u'/home/tomcat/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /bin/ansible python version = 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
配置hosts /etc/ansible/hosts
[msa_server] 192.168.14.5 [task_server] 192.168.14.6
Note: Here I am with two nodes respectively presentation module ansible successful and unsuccessful push to do under compare
Configuring ssh
In the tomcat user ansible host, execute
ssh-keygen -t rsa
[tomcat@RZ-DEV-COM-XZSX-JENKINS-01 ansible]$ cd /home/tomcat/.ssh/ [tomcat@RZ-DEV-COM-XZSX-JENKINS-01 .ssh]$ ll total 8 -rw------- 1 tomcat tomcat 1675 Jan 17 23:47 id_rsa -rw-r--r-- 1 tomcat tomcat 415 Jan 17 23:47 id_rsa.pub
We can see the keys that have been generated, and then copy the public key to the 192.168.14.5
ssh-copy-id -i root@192.168.14.5
Free test results secret
[tomcat@RZ-DEV-COM-XZSX-JENKINS-01 .ssh]$ ssh root@192.168.14.5 Warning: Permanently added '192.168.14.5' (ECDSA) to the list of known hosts. Last login: Sun Jan 19 15:17:56 2020 from 192.168.14.2 [root@RZ-DEV-APP-XZSX-MSA-01 ~]# [root@RZ-DEV-APP-XZSX-MSA-01 ~]# cd /root/.ssh/ [root@RZ-DEV-APP-XZSX-MSA-01 .ssh]# ll total 4 -rw------- 1 root root 415 Jan 19 11:21 authorized_keys [root@RZ-DEV-APP-XZSX-MSA-01 .ssh]# cat authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzbdGnAUp9CeySymKNeo6mlfBDijsXM3ptP0P+uO/3XUMlZiFujsACb05KThZ+Q8JpYRNNijnL72RHoBix+E618w2TqCtAQ9pzxnO/dgcCgoZVWc9nP8HQIkr+mOEKQHfK8yQZlQ0q+3XEr3vRcjNWKzMt7yPSj8l/F9MWBUtGYGffwVDNfv8p3Y4SRHaL4/ExFmZ7kGtmIqEb6TWeEJhLwXtodOlqXpV3uJAHzHelRDKiecJCIwi2kj/BhmAIU1KKAk/MrLjCYTkLI1udhNxfnxc5RELfwUQ+rnXHkSa661p7ysOSSIj+wdkJUL719vVu8EZhYQw+ddSAHrX6c/31 tomcat@RZ-DEV-COM-XZSX-JENKINS-01 [root@RZ-DEV-APP-XZSX-MSA-01 .ssh]#
Test our ansible hosts file, pay attention, because it is produced under tomcat user ssh keys, we need to execute the following command in the user tomcat
[tomcat@RZ-DEV-COM-XZSX-JENKINS-01 ~]$ ansible all -m ping 192.168.14.6 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added '192.168.14.6' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey,password).\r\n", "unreachable": true }192.168.14.5 | SUCCESS => { "changed": false, "ping": "pong" }
Because 192.168.14.5 can see this machine we configure ssh keys under the tomcat user, so the result is a success, and 192.168.14.6 is not configured, an error is reported, well let's be configured on this server under 14.6 ssh
[tomcat@RZ-DEV-COM-XZSX-JENKINS-01 ~]$ ssh-copy-id -i root@192.168.14.6 /bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys Warning: Permanently added '192.168.14.6' (ECDSA) to the list of known hosts. root@192.168.14.6's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh '[email protected]'" and check to make sure that only the key(s) you wanted were added. [tomcat@RZ-DEV-COM-XZSX-JENKINS-01 ~]$ ssh root@192.168.14.6 Warning: Permanently added '192.168.14.6' (ECDSA) to the list of known hosts. Last failed login: Sun Jan 19 15:32:22 CST 2020 from 192.168.14.2 on ssh:notty There were 2 failed login attempts since the last successful login. Last login: Fri Jan 17 20:44:08 2020 from 192.168.14.2 [root@RZ-DEV-APP-XZSX-TASK-01 ~]# cat /root/.ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzbdGnAUp9CeySymKNeo6mlfBDijsXM3ptP0P+uO/3XUMlZiFujsACb05KThZ+Q8JpYRNNijnL72RHoBix+E618w2TqCtAQ9pzxnO/dgcCgoZVWc9nP8HQIkr+mOEKQHfK8yQZlQ0q+3XEr3vRcjNWKzMt7yPSj8l/F9MWBUtGYGffwVDNfv8p3Y4SRHaL4/ExFmZ7kGtmIqEb6TWeEJhLwXtodOlqXpV3uJAHzHelRDKiecJCIwi2kj/BhmAIU1KKAk/MrLjCYTkLI1udhNxfnxc5RELfwUQ+rnXHkSa661p7ysOSSIj+wdkJUL719vVu8EZhYQw+ddSAHrX6c/31 tomcat@RZ-DEV-COM-XZSX-JENKINS-01 [root@RZ-DEV-APP-XZSX-TASK-01 ~]#
[tomcat@RZ-DEV-COM-XZSX-JENKINS-01 ~]$ ansible all -m ping 192.168.14.6 | SUCCESS => { "changed": false, "ping": "pong" } 192.168.14.5 | SUCCESS => { "changed": false, "ping": "pong" } [tomcat@RZ-DEV-COM-XZSX-JENKINS-01 ~]$
Install git
Our jenkins need to download the project from the git, so you need to install the server git jenkins
yum -y install git
[tomcat@RZ-DEV-COM-XZSX-JENKINS-01 ~]$ git --version git version 1.8.3.1
jenkins configure git
Jenkins plug-in installation
Wait for the installation to complete
jenkins configure global information
Above jdk, maven, ansible pressing need on their path to the server configuration, so far our jenkins basic configuration is complete, I will pay you in the next chapter to create a new java and publish multi-module single module