LoginSignup
2
2

More than 5 years have passed since last update.

ansible をソースコードからインストール

Posted at

ansibleの安定版にて ec2 module でawscliで使ってる profile をセットしても失敗するという現象が発生しました。ちなみに、 ec2_group module の方は問題なく動きます。
そこで開発版を試してみたところ上手く動いたのですが、公式サイトの インストール手順 にある hacking/env-setup が環境変数を思いっきり追加しまくってちょっと扱うのが難しいので、virtualenv環境作ってsetup.pyを使った方法でインストールしました。
実行環境はOS X Yosemite + MacPortsです。virtualenv-2.7コマンドはvirtualenvに置き換えても良いでしょう。

virtualenv-2.7 env
source env/bin/activate
pip install --upgrade pip
pip install paramiko PyYAML Jinja2 httplib2
pip install boto awscli
git clone git://github.com/ansible/ansible.git --recursive
python setup.py install
cd ..
rehash
which ansible

awscliをこのタイミングで入れてるのはただの趣味です。
which ansibleでvirtualenvの方に出てくればいちおうOK

/Users/hoge/dev/unkoproject/server/infra/env/bin/ansible

次にawscliでprofileを作ります。

aws configure --profile toilet

あとはlocal_actionを使うのを適当に作って実行します。

echo "localhost ansible_python_interpreter=`which python`" > hosts
vi unko.yml
ansible-playbook -i hosts unko.yml

unko.ymlは以下の様な内容です。

- name: Unko
  hosts: 127.0.0.1
  connection: local
  tasks:
    - name: Create Security Group
      local_action:
        module: ec2_group
        name: unko_group
        description: Security Group for Unko
        region: ap-northeast-1
        profile: toilet
        rules:
          - proto: tcp
            from_port: 22
            to_port: 22
            cidr_ip: 0.0.0.0/0
          - proto: tcp
            from_port: 80
            to_port: 80
            cidr_ip: 0.0.0.0/0
          - proto: tcp
            from_port: 443
            to_port: 443
            cidr_ip: 0.0.0.0/0
          - proto: tcp
            from_port: 25
            to_port: 25
            cidr_ip: 0.0.0.0/0

    - name: Unko Web Server Instance
      local_action:
        module: ec2
        region: ap-northeast-1
        keypair: ToiletKey
        group: unko_group
        instance_type: t2.micro
        image: ami-936d9d93
        count: 1
        wait: yes
        profile: toilet
      register: ec2

    - name: Add Web Server instance to host group
      local_action: add_host hostname={{ item.public_ip }} groupname=unko
      with_items: ec2.instances

    - name: Add tag to instances
      local_action: ec2_tag resource={{ item.id }} region=ap-northeast-1 state=present profile=toilet
      with_items: ec2.instances
      args:
        tags:
          Name: Unko

    - name: Wait for SSH to become available
      pause: minutes=1

もうちょっとネーミングセンスあればよかった。

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