概要
centos7 に ansible を epel から rpm でインストールした場合、get_url で github からファイルを取得しようとすると証明書のエラーになります。その対処法についてです。
エラーになるケース
yum update をします。
yum -y update
ansible を epel からインストールします。
$ yum install -y epel-release
$ yum install -y ansible
ansible 1.9.4 がインストールされました。
playbook では get_url で github の TOP ページを取得します。
(ファイル名を playbook.yml とします)
- hosts: all
connection: local
environment:
https_proxy: "{{ lookup('env', 'https_proxy') }}"
tasks:
- name: Get github
get_url:
url: "https://github.com/"
dest: /tmp/github.top
hosts は localhost を定義します。
(ファイル名を hosts とします)
localhost
playbook を実行します。
ansible-playbook -i hosts playbook.yml
証明書が github.com のものじゃないよ、というエラーになります。
TASK: [Get github] ************************************************************
failed: [localhost] => {"failed": true}
msg: SSL Certificate does not belong to github.com. Make sure the url has a certificate that belongs to it or use validate_certs=False (insecure)
FATAL: all hosts have already failed -- aborting
エラーの原因
こちらに記載がありました。
https://github.com/ansible/ansible/issues/11579
github では SNI が使用されています。
ansible を SNI 対応版(2系)に更新する必要があります。
※上記リンクでは python 2.7.9 以降が必要とありますが、2.7.5(centos7 のプリインストールバージョン) でも問題ありませんでした。 ⇒怪しいので python 2.7.11 をインストールします。
対応
ansible v2.0.0.1-1 のインストール
まず、ansible のソースから rpm パッケージを作成したり、ansible をインストールするのに必要なツールをインストールします。
$ yum install -y epel-release
$ yum install -y rpm-build python2-devel python-setuptools PyYAML python-jinja2 python-paramiko python-six python-httplib2 python-keyczar sshpass
rpm パッケージを作成してインストールします。
$ cd /usr/src
$ wget https://github.com/ansible/ansible/releases/download/v2.0.0.1-1/ansible-2.0.0.1.tar.gz
$ tar xvf ansible-2.0.0.1.tar.gz
$ cd ansible-2.0.0.1
$ make rpm OFFICIAL=yes
$ rpm -Uvh ./rpm-build/ansible-*.noarch.rpm
python 2.7.11 のインストール
個人的に python のバージョン管理ツールを使ったことがないので、単純にソースからインストールします。
/opt/python にインストールします。
$ mkdir /opt/python
$ cd /usr/src
$ wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
$ tar xvf Python-2.7.11.tgz
$ cd Python-2.7.11
$ ./configure --prefix=/opt/python
$ make
$ make install
$ python -V
Python 2.7.5
$ /opt/python/bin/python -V
Python 2.7.11
playbook 内で使用する python を指定
playbook.yml の tasks の先頭に以下を追記します。
- name: set ansible_python_interpreter
set_fact: ansible_python_interpreter="/opt/python/bin/python"
playbook を再度実行
github から取得することができました!
TASK [Get github] **************************************************************
changed: [localhost]
Vagrantfile
上の環境(centos7 ansible 2.0)を構築する Vagranfile をこちら に記載しました。