Centos7 uses Ansible to install Chinese fonts in batches

Demand background

Chinese characters are garbled when Java generates image watermark under Centos7 because Chinese fonts are not installed.

Install Chinese fonts

The following are detailed steps for manually installing Chinese fonts based on Centos7. When there are more servers in the test or production environment, it is recommended to use automated operation and maintenance tools.

1# Install font library
 2 $ yum -y install fontconfig
 34# Check if there are Chinese fonts
 5 $ fc-list :lang=zh
 67# Create Chinese font catalog
 8 $ mkdir /usr/share/fonts/chinese
 910# C in windows:\Windows\Find the corresponding font in the Fonts directory and copy it to the chinese directory. Here we take Songti as an example
11 $ scp simsun.ttc simsunb.ttf root@xxxxx:/usr/share/fonts/chinese
1213# Check if there are Chinese fonts
14 $ fc-list :lang=zh
15 /usr/share/fonts/chinese/simsun.ttc: SimSun,Song Ti:style=Regular,conventional
16 /usr/share/fonts/chinese/simsun.ttc: NSimSun,New Song:style=Regular,conventional

Ansible batch installation

Usually there are many servers in the test or production environment. The following records how to use Ansbile to install Chinese fonts in batches.

1# ansbile playbook execution
 2 $ ansible-playbook fonts.yml
 34# Verify that all servers are valid
 5 $ ansible all -m shell -a "fc-list :lang=zh"
 6 sever01 | SUCCESS | rc=0>>7/usr/share/fonts/chinese/simsun.ttc: SimSun,Song Ti:style=Regular,conventional
 8 /usr/share/fonts/chinese/simsun.ttc: NSimSun,New Song:style=Regular,conventional
 9 sever02 | SUCCESS | rc=0>>10/usr/share/fonts/chinese/simsun.ttc: SimSun,Song Ti:style=Regular,conventional
11 /usr/share/fonts/chinese/simsun.ttc: NSimSun,New Song:style=Regular,conventional
12......

Contents of fonts.yml:

1- - - 2- name: Install Chinese Fonts.3  hosts: all 
4 remote_user: root
5 become: yes
6 become_method: sudo
7 become_user: root
8 roles:9- fonts

Ansible playbook directory structure (useless directories removed):

1 $ tree roles/fonts
2 roles/fonts
3 ├── files
4 │   ├── simsun.ttc
5 │   └── simsunb.ttf
6 └── tasks
7 └── main.yml
892 directories,3 files

task/main.yml content:

1- - - 2# tasks file for fonts
 34- name: install fontconfig.5  yum:6    name:"{{ item }}"7    state: installed
 8 with_items:9- fontconfig
10 ignore_errors:true1112- name: mkdir /usr/share/fonts/chinese.13  file:14    path:/usr/share/fonts/chinese
15 state: directory
16 mode:07551718- name: Copy fonts to agent.19  copy:20    src:"{{ item }}"21    dest:/usr/share/fonts/chinese
22 with_items:23- simsun.ttc
24- simsunb.ttf

Recommended Posts

Centos7 uses Ansible to install Chinese fonts in batches
How to install PHP7.4 in CentOS
How to install HDP2.6 in Centos7.2
How to install Android SDK in centos7
Centos8 uses Apache httpd2.4.37 to install web server steps in detail
Centos8 uses yum to install mongodb 4.2 method
Centos7 uses yum to install pip, ipython
Centos7 uses yum to install Apache, mariadb, PHP
How to install php7.3 in centos8 custom directory
Install MySQL5.7 in centos7
Install php in centos
Install redis5.0 in CentOS7
Centos7.6 method to install Tomcat-8.5.39
Update gcc to 6.4.0 in centos
Detailed steps to install and configure k8s cluster in centos 7
How to install Helm in Ubuntu
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
Install JDK8 in rpm on CentOS7
How to install Memcached on CentOS 8
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
[Introduction to redis] Install redis under Centos
Minimal install JDK 1.8 tutorial in CentOS 7
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
Install MySql with Docker in CentOS7
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install mysql in Ubuntu 14.04
Install Percona Server database (in CentOS 8)
How to install Yarn on CentOS 8
Install java in yum mode in Centos
How to install Nginx on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
Install Python3 and ansible under CentOS8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
Install Centos7 operating system in Docker
How to install htop on CentOS 8
How to install mysql in Ubuntu 14.04
centos7 .*tar package to install MySQL5.7
How to install TeamViewer on CentOS 8
How to install MariaDB on CentOS 8