アーカイブ「2016年03月」

ansibleでcentos7のdockerコンテナをプロビジョンしているのだが、

日本語化するのがなかなか大変だったので、手順を記載しておく。

 

以下はプレイブック。

---
- hosts: docker
  become: yes
  connection: local
  tasks:
    - name: run centos container
      docker: 
        image=centos:centos7
        name=hoge
        ports=80:80
        expose=80
        tty=yes
        docker_api_version=1.20
        hostname=hoge-docker
        privileged=yes
        command=/sbin/init
        env='LANG=ja_JP.UTF-8'
      tags: docker

- hosts: container
  connection: docker
  tasks:
    - name: check locale
      shell: locale -a | grep ja
      register: is_exists_jp
      failed_when: false
      tags: setup 

   - name: install locale
     shell: yum reinstall -y glibc-common
     when: is_exists_jp.stdout == ''
     tags: setup

 

以下は、hosts。

[docker]
localhost
 
[container]
docker

 

これで、

$ ansible-playbook -i hosts playbook.yml

とすると、日本語化されたcentos7のdockerコンテナが利用できます。

 

ポイントは、

  • コンテナ作成時のenvの指定
  • コンテナ内でのglibc-commonのreinstall

となります。

shellでyum叩いてるから、ワーニングでるけど、しょうがないかな。

 

投稿日時:2016年03月24日 09:40   カテゴリー:ansible   [コメントがあればどうぞ]

最近ansibleを始めた。

動機としては、

  • redhatが買収した
  • chefはめんどい
  • 2.0からdockerプラグインが追加された

といったところ。

 

dockerは積極的ではないが、

構成管理ツールの必要性は認識してたから、ちょうどよいかなと。

 

ただ、ある条件の元で、冪等性が確保できないケースがあった。

以下である。

- name: configure httpd before
  lineinfile: dest=/etc/httpd/conf/httpd.conf state=present insertbefore={{item.insertbefore}} line={{item.line}} backup=yes
  with_items:
    - insertbefore: '^IncludeOptional conf\.d/\*\.conf'
  line: "<VirtualHost *:80>\n</VirtualHost>"
  tags: httpd

これは、httpdにおいて、
デフォルトVHを設定している際に、
VirtualHostディレクティブに改行を挟んでいるのだが、
これが原因で、二度目の実行の際、さらに追加されるというものであった。

ソース確認してないからわからないが、
改行を入れると、冪等性が確保されないのかもしれない。

以上

投稿日時:2016年03月16日 16:10   カテゴリー:ansible   [コメントがあればどうぞ]