LoginSignup
3
3

More than 5 years have passed since last update.

Ansible2のfindモジュールを利用したかったけどちょっと手間取ったのでメモ

Last updated at Posted at 2015-11-24

Ansible2のfindモジュールを利用したかったけどちょっと手間取ったのでメモ

環境

  • CentOS7(x86_64)
  • Vagrant

どうやらyumではなく、GitHubからソースを取得してコンパイルする必要があるようだ。

手順

下記の公式の手順を参考に作業を実施します。
http://docs.ansible.com/ansible/intro_installation.html#running-from-source

下記のコマンドでエラーが発生した。。。

$ sudo pip install paramiko PyYAML Jinja2 httplib2 six

    gcc -pthread -fno-strict-aliasing -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=          ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -pipe -Wall -Wp,-D_FORTIFY_SOURC          E=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOU          RCE -fPIC -fwrapv -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/MD2.c -o build/temp.lin          ux-x86_64-2.7/src/MD2.o
    src/MD2.c:31:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-DJuN7X/pycrypto/setup.py';exec(compile          (getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-c          G6Sjn-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-buil          d-DJuN7X/pycrypto

調べてみるとpythonのdevelopツールが無い事が原因らしい。
ということで

$ sudo yum install python-devel

上記パッケージ導入後に同じコマンドを実行したところ正常に終了しました。
後続の作業はエラーも無しにそのまま実施できました。

インストール成功

バージョンを確認して問題なさそう

$ ansible --version
ansible 2.0.0
  config file =
  configured module search path = Default w/o overrides

いざテスト!

$ echo "127.0.0.1" > ~/ansible_hosts
$ ansible all -m ping --ask-pass
SSH password:
127.0.0.1 | FAILED! => {
    "failed": true,
    "msg": "ERROR! to use the 'ssh' connection type with passwords, you must ins                                              tall the sshpass program"
}

あれ、エラーになる。sshpassを入れてくれとのこと。
じゃぁその通りにしましょうか。

$ sudo rpm -ivh http://ftp.iij.ad.jp/pub/linux/fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
$ sudo yum install sshpass

いざテスト!(その2)

$ ansible all -m ping --ask-pass
SSH password:
127.0.0.1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

お、通信出来た。そしたら、最後に使いたかったfindコマンドを実行してみる。

$ ansible all -m find -a "paths=." --ask-pass
SSH password:
127.0.0.1 | SUCCESS => {
    "changed": false,
    "examined": 10,
    "files": [
        {
            "atime": 1448404038.6609726,
            "ctime": 1448403725.0179846,
            "dev": 64769,
            "gid": 1000,
            "inode": 611328,
            "isblk": false,
            "ischr": false,
            "isdir": false,
            "isfifo": false,
            "isgid": false,
            "islnk": false,
            "isreg": true,
            "issock": false,
            "isuid": false,
            "mode": "0664",
            "mtime": 1448403725.0179846,
            "nlink": 1,
            "path": "ansible_hosts",
            "rgrp": true,
            "roth": true,
            "rusr": true,
            "size": 10,
            "uid": 1000,
            "wgrp": true,
            "woth": false,
            "wusr": true,
            "xgrp": false,
            "xoth": false,
            "xusr": false
        }
    ],
    "matched": 1,
    "msg": ""
}

正常に、ファイル情報が取得できました。

最後に

やっぱり依存関係とか考えるとyumで入れるのが楽ですね。でも、最新の機能が提供されてない一時的にこういう作業も仕方なしっと。

3
3
2

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
3
3