Centos7 使用 Ansible 批量安装中文字体

需求背景【Centos7 使用 Ansible 批量安装中文字体】centos7 下 JAVA 生成图片水印时中文乱码,原因是没有安装中文字体 。
安装中文字体以下是基于 Centos7 手动安装中文字体的详细步骤 。当测试或者生产环境服务器比较多的时候,建议使用自动化运维工具 。
# 安装字体库$ yum -y install fontconfig# 查看是否有中文字体$ fc-list :lang=zh# 创建中文字体目录$ mkdir /usr/share/fonts/chinese# 在 windows 的 C:WindowsFonts 目录下找到相应的字体 copy 到 chinese 目录下,这里以 宋体 为例$ scp simsun.ttc simsunb.ttf root@xxxxx:/usr/share/fonts/chinese# 查看是否有中文字体$ fc-list :lang=zh/usr/share/fonts/chinese/simsun.ttc: SimSun,宋体:style=Regular,常规/usr/share/fonts/chinese/simsun.ttc: NSimSun,新宋体:style=Regular,常规Ansible 批量安装通常测试或者生产环境服务器比较多,下面记录如何使用 Ansbile 来批量安装中文字体 。
# ansbile playbook 执行$ ansible-playbook fonts.yml# 验证所有服务器是否生效$ ansible all -m shell -a "fc-list :lang=zh"sever01 | SUCCESS | rc=0 >>/usr/share/fonts/chinese/simsun.ttc: SimSun,宋体:style=Regular,常规/usr/share/fonts/chinese/simsun.ttc: NSimSun,新宋体:style=Regular,常规sever02 | SUCCESS | rc=0 >>/usr/share/fonts/chinese/simsun.ttc: SimSun,宋体:style=Regular,常规/usr/share/fonts/chinese/simsun.ttc: NSimSun,新宋体:style=Regular,常规......fonts.yml 内容:
---- name: Install Chinese Fonts.hosts: allremote_user: rootbecome: yesbecome_method: sudobecome_user: rootroles:- fontsansible playbook 目录结构(删除了无用目录):
$ tree roles/fontsroles/fonts├── files│├── simsun.ttc│└── simsunb.ttf└── tasks└── main.yml2 directories, 3 filestask/main.yml 内容:
---# tasks file for fonts- name: install fontconfig.yum:name: "{{ item }}"state: installedwith_items:- fontconfigignore_errors: true- name: mkdir /usr/share/fonts/chinese.file:path: /usr/share/fonts/chinesestate: directorymode: 0755- name: Copy fonts to agent.copy:src: "{{ item }}"dest: /usr/share/fonts/chinesewith_items:- simsun.ttc- simsunb.ttf



    推荐阅读