LoginSignup
0
0

More than 5 years have passed since last update.

Ansibleを使ってCentOS上にphp-mcryptをインストールしようとしたが、 "--check"オプションの挙動でハマった話

Last updated at Posted at 2018-12-07

背景

  1. Ansible で検証環境では問題なく動作していたスクリプトが、本番環境適用直前に --check オプション( dry-run )付きで実行するとエラーが出る

環境

OS

CentOS7

Ansibleスクリプト

事象の再現のために簡単なAnsibleスクリプトを作成し調査

- hosts:
    - localhost
  tasks:
  - yum: name=epel-release state=latest

  - yum: name={{ item }} state=present
    with_items:
      - php
      - php-common
      - php-mcrypt

実行結果

[root@068a4db82a8f app]# ansible-playbook --check -i hosts php-mcrypt.yml
[DEPRECATION WARNING]: DEFAULT_SUDO_USER option, In favor of become which is a generic framework .
This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

PLAY [localhost] ***********************************************************************************

TASK [Gathering Facts] *****************************************************************************
ok: [localhost]

TASK [yum] *****************************************************************************************
changed: [localhost]

TASK [yum] *****************************************************************************************
failed: [localhost] (item=[u'php', u'php-common', u'php-mcrypt']) => {"changed": false, "item": ["php", "php-common", "php-mcrypt"], "msg": "No package matching 'php-mcrypt' found available, installed or updated", "rc": 126, "results": ["No package matching 'php-mcrypt' found available, installed or updated"]}
        to retry, use: --limit @/app/php-mcrypt.retry

PLAY RECAP *****************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=1

原因

よく考えると当たり前のことだが、 php-mcrypt インストールのために必要な yumリポジトリ ( epel-release ) が、 --check オプション付きで実行した場合にはインストールされていないため。

--check オプション無しで実行すれば正常終了する。

[root@068a4db82a8f app]# ansible-playbook -i hosts php-mcrypt.yml
[DEPRECATION WARNING]: DEFAULT_SUDO_USER option, In favor of become which is a generic framework .
This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

PLAY [localhost] ***********************************************************************************

TASK [Gathering Facts] *****************************************************************************
ok: [localhost]

TASK [yum] *****************************************************************************************
changed: [localhost]

TASK [yum] *****************************************************************************************
changed: [localhost] => (item=[u'php', u'php-common', u'php-mcrypt'])

PLAY RECAP *****************************************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0

一度 --check オプションなしで実行すれば、その後は --check オプション付きでもエラーは出ない。

[root@068a4db82a8f app]# ansible-playbook --check -i hosts php-mcrypt.yml
[DEPRECATION WARNING]: DEFAULT_SUDO_USER option, In favor of become which is a generic framework .
This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

PLAY [localhost] ***********************************************************************************

TASK [Gathering Facts] *****************************************************************************
ok: [localhost]

TASK [yum] *****************************************************************************************
ok: [localhost]

TASK [yum] *****************************************************************************************
ok: [localhost] => (item=[u'php', u'php-common', u'php-mcrypt'])

PLAY RECAP *****************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0
0
0
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
0
0