This is my 11th day of the August Challenge.

The paper

In the two articles “Ansible Automation: Implementation of Operating System Initialization” and “Ansible Automation: Custom Installation of Basic Software”, we use Ansible to meet the operation requirements on the character interface, but it is not friendly. We wanted everyone on the team to be able to use it seamlessly, so we needed a graphical interface to improve usability.

Here, we use Jenkins+Ansible to realize the graphical parameterized construction process:

We enter the IP, select different tags based on the selected PLAYBOOK, and automate our needs on demand.

So let’s see what we’re going to do.

Ansible

As our configuration hub, Ansible relies on the Playbook to orchestrate all kinds of automated operations. In addition, the whole choreography process is subdivided with the help of Tag, which helps us to carry out diversified combination and flexible reuse.

In the infrastructure construction phase, we need to initialize the operating system and install basic components. The specific implementation of these two scenarios is described in Ansible Automation: Specific Implementation of Operating System Initialization and Ansible Automation: “Custom Installation of Basic Software” is explained. Here we only show the directory structure. I hope you can make reasonable arrangements according to the directory functions of Ansible when realizing specific requirements.

1. Initialize basic components

Ansible PlayBook is used to install various basic components such as FileBeat, Java, Python, and Nginx.

Roles /software_install/ ├─ files │ ├─ filebeat │ ├─ filebeat-6.43.- x86_64. RPM │ │ └ ─ ─ filebeat. Yml │ ├ ─ ─ Java │ │ ├ ─ ─ app. Tar. Gz │ │ ├ ─ ─ the app.zip│ │ ├ ─ ─ the data.zip│ │ └ ─ ─ jdk18.. 0 _40.zip│ ├─ Heavy Metal Guitar School │ ├─ Heavy Metal Guitar School - Heavy Metal Band.zip│ │ ├ ─ ─ nginx - module - VTS - master.zip│ │ ├ ─ ─ nginx_upstream_check_module - master.zip│ │ └ ─ ─ tengine -2.32..tar.gz │ ├ ── python │ ├ ── python -3.7. 0.tgz ├ ─ ─ handlers │ └ ─ ─ the main, yml ├ ─ ─ the tasks │ ├ ─ ─ filebeat. Yml │ ├ ─ ─ Java. Yml │ ├ ─ ─ the main, yml │ ├ ─ ─ nginx. Yml │ ├ ─ ─ ├ ─ ch.pdf │ ├ ─ ch.pdfvars└ ─ ─ the main ymlCopy the code

2. System initialization

Ansible PlayBook is used for operating system initialization, such as time synchronization, kernel parameters, user initialization, environment variables, and security baseline.

Roles/os_init ├ ─ ─ files │ ├ ─ ─ ansible_key │ │ └ ─ ─ id_rsa. Pub │ ├ ─ ─ blueking_key │ │ └ ─ ─ id_rsa. Pub │ ├ ─ ─ CentOS6 - Base - LAN. Repo │ ├ ─ ─ CentOS7 - Base - LAN. Repo │ ├ ─ ─ the client. The XML │ ├ ─ ─ deploy_key │ │ └ ─ ─ id_rsa. Pub │ ├ ─ ─ Epel7 - LAN. Repo │ ├ ─ ─ zabbix agent -3.014.-1.El7. X86_64. RPM │ ├ ─ ─ zabbix agent -4.21.-1.El6. X86_64. RPM │ ├ ─ ─ zabbix - release -3.0-1.El7. Noarch. RPM │ ├ ─ ─ zabbix - release -4.2-1.El6. Noarch. RPM │ ├ ─ ─ zabbix - sender -3.014.-1.El7. X86_64. RPM │ └ ─ ─ zabbix - sender -4.21.-1.El6. X86_64. RPM ├ ─ ─ handlers │ └ ─ ─ the main, yml ├ ─ ─ the tasks │ ├ ─ ─dir. Yml │ ├ ─ ─ DNS. Yml │ ├ ─ ─ init_pkg. Yml │ ├ ─ ─ the iptables. Yml │ ├ ─ ─ limits. Yml │ ├ ─ ─ the main, yml │ ├ ─ ─ the NTP. Yml │ ├ ─ ─ profile. Yml │ ├ ─ ─ rc. Local. Yml │ ├ ─ ─ repo. Yml │ ├ ─ ─ rsyslog. Yml │ ├ ─ ─ safe. Yml │ ├ ─ ─ selinux. Yml │ ├ ─ ─ SSHD. Yml │ ├ ─ ─ sysctl. Yml │ ├── user.yml │ ├── zabbix_pro.yml ├── templates │ ├─ sysctl.confvars├ ─ ─ the main ymlCopy the code

Tags can be added according to the actual situation. For example, there are many tags in the system initialization, but we do not use all of them.

Jenkins

We use Jenkins’ feature-rich plugins to meet different requirements.

1. Parametric construction

Jenkins’ built-in “String Parameter” and “Choice Parameter”, though to some extent full of our needs for common parameters, are not sufficient for our linkage of selection parameters (i.e. active selection reaction parameters), such as the selection of system initialization script, which can be linked to its associated label.

Here we choose to install the “Active Choices plugin-in “Plugin to enable Active selection of response parameters. “Active Choices Reactive Parameter” is combined with “multi-line String Parameter” and “Choice Parameter” to realize parameterized Choice.

(1) Multi-line String Parameter

Multi-line string parameters, easy for us to input multiple IP, to achieve batch operation.

(2) Choice Parameter

This Parameter can be associated with the Active Choices Reactive Parameter Tag.

(3) Active Choices Reactive Parameter

This parameter implements the linkage between the PLAYBOOK and the TAG through the Groovy script.

Referenced Parameters allow you to set the associated source parameters.

Linkage between parameters can be realized after the above Settings:

2. Associate with Ansbile

Jenkins can be associated with Ansible through “Ansible Plugin “. Of course, Jenkins can also be implemented using shell without installing plug-ins.

Since common users are used to perform operations, ansible needs to use the -b parameter to lift the weight during installation.

conclusion

Through Jenkins + Ansible, we help infrastructure construction in graphical interface and improve operation friendliness. Hopefully, Jenkins is not just a DevOps player, but also an automated build player.

We are not using Jenkins Pipeline here because the orchestration of Ansible Playbook is implemented to some extent at the operating system level.