LoginSignup
22
26

More than 5 years have passed since last update.

CentOS 7(RHEL 7) 初期設定 Ansible 編

Last updated at Posted at 2018-04-06

はじめに

CentOS 7(RHEL 7) 初期設定 の 内容を Ansible の Playbook に 置き換えてみます。

ロケール、タイムゾーンの設定

ロケールの設定,Winボタン付きの日本語キーボード設定
- name: set locale
  shell: localectl set-locale LANG=ja_JP.utf8

# Mac の 場合は「us-mac」を指定
- name: change keymap to Japanese 109
  shell: localectl set-keymap jp-OADG109A

- name: change x11 keymap to Japanese 109
  shell: localectl set-x11-keymap jp-OADG109A
タイムゾーンの設定
- name: set timezone to Asia/Tokyo
  timezone:
    name: Asia/Tokyo

Proxyの設定

サーバのProxy設定
# proxy.sh を templetes ディレクトリに配置
- name: set proxy.sh
  template:
    force: yes
    src: proxy.sh
    dest: /etc/profile.d/proxy.sh
    owner: root
    group: root
    mode: 0644
  register: proxy_file
- name: source proxy.sh
  shell: source /etc/profile.d/proxy.sh
  when:
  - proxy_file is changed
yumのProxy設定
# /etc/yum.conf に Proxy設定を追加
- name: set yum proxy
  lineinfile:
    dest: /etc/yum.conf
    state: present
    regexp: "^proxy=.*$"
    insertafter: EOF
    line: "proxy={{ http_proxy }}"
パッケージの最新化
- name: yum update
  yum:
    name: '*'
    state: latest
    skip_broken: yes
rpmのproxy設定
# macros を templates ディレクトリに配置
- name: set rpm proxy
  template:
    force: yes
    src: macros
    dest: /etc/rpm/macros
    owner: root
    group: root
    mode: 0644
wgetインストール
- name: install wget
  yum:
    name: wget
    state: latest
    skip_broken: yes
wgetのproxy設定
# /etc/wgetrc に Proxy設定を追加
- name: set wget proxy
  lineinfile:
    dest: /etc/wgetrc
    state: present
    regexp: "^{{ item }} = .*$"
    insertafter: "^#{{ item }}"
    line: "{{ item }} = {{ http_proxy }}"
  with_items:
    - http_proxy
    - https_proxy
    - ftp_proxy
gitのインストール
- name: install the latest version of git
  yum:
    name: git
    state: latest
gitのproxy設定
- name: set git proxy
  shell: "git config --global {{ item }} {{ http_proxy }}"
  ignore_errors: yes
  with_items:
    - http.proxy
    - https.proxy

社内CA証明書の設定

# CA証明書のハッシュ値を取得(証明書が変わった時にエラーにする為)
sha256sum xxx.ca
ca_sha256(ハッシュ値)
社内CA証明書の設定
- name: set Local CA Certificate
  get_url:
    url: "{{ ca_url }}"
    dest: /etc/pki/ca-trust/source/anchors
    checksum: "sha256:{{ ca_sha256 }}"
    use_proxy: no
    force: yes
  register: downloaded_ca

- name: extract ca
  shell: update-ca-trust extract
  when:
  - downloaded_ca is changed

さいごに

具体的なソースは GitHub を ご参照ください。

次は、今回作成したロールを Ansible Galaxy に登録して再利用する方法 を 紹介したいと思います。

22
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
26