** Features of Ansible ** --It is a tool that automates server construction without agents. --It connects to the machine running sshd with SSH and builds the environment. --Write the configuration file in YAML. No programming knowledge (Ruby, Python, etc.) is required. --It's easier than chef to build a few to dozens of servers.
** Preparing the environment ** Please refer to the previous article. Ansible First Step
playbook.yml
The lineinfile module replaces the character string.
I have a symbolic link in the file module.
- hosts: all
remote_user: ec2-user
become: true
tasks:
- name: set LANG
lineinfile: >
dest=/etc/sysconfig/i18n
regexp='LANG=.*'
line='LANG=ja_JP.utf8'
- name: set ZONE
lineinfile: >
dest=/etc/sysconfig/clock
regexp='ZONE=.*'
line='ZONE="Asia/Tokyo"'
- name: set UTC
lineinfile: >
dest=/etc/sysconfig/clock
regexp='UTC=.*'
line='UTC=false'
- name: link localtime
file: >
src=/usr/share/zoneinfo/Asia/Tokyo
dest=/etc/localtime
state=link
force=yes
ansible-playbook I will try it.
$ ansible-playbook playbook.yml
target01 : ok=5 changed=4 unreachable=0 failed=0
** Before playing playbook **
$ env | grep LANG
LANG=en_US.UTF-8
$ cat /etc/sysconfig/i18n
LANG=en_US.UTF-8
$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
$ date
Thu Jun 30 15:05:14 UTC 2016
$ strings /etc/localtime
TZif2
TZif2
UTC0
$ cat /etc/sysconfig/clock
ZONE="UTC"
UTC=true
** After running playbook ** When you log in again, the settings are changed as follows.
$ env | grep LANG
LANG=ja_JP.utf8
$ cat /etc/sysconfig/i18n
LANG=ja_JP.utf8
$ locale
LANG=ja_JP.utf8
LC_CTYPE="ja_JP.utf8"
LC_NUMERIC="ja_JP.utf8"
LC_TIME="ja_JP.utf8"
LC_COLLATE="ja_JP.utf8"
LC_MONETARY="ja_JP.utf8"
LC_MESSAGES="ja_JP.utf8"
LC_PAPER="ja_JP.utf8"
LC_NAME="ja_JP.utf8"
LC_ADDRESS="ja_JP.utf8"
LC_TELEPHONE="ja_JP.utf8"
LC_MEASUREMENT="ja_JP.utf8"
LC_IDENTIFICATION="ja_JP.utf8"
LC_ALL=
[ec2-user@ip-172-31-23-139 ~]$ date
Friday, July 1, 2016 00:27:46 JST $ strings /etc/localtime TZif2 JCST TZif2 JCST JST-9 $ cat /etc/sysconfig/clock ZONE="Asia/Tokyo" UTC=false ```
The end (^^) v
Recommended Posts