[PYTHON] Install ansible from source code

In the stable version of ansible, even if I set the profile used by awscli in ec2 module, it failed. By the way, ec2_group module works fine. So I tried the development version and it worked, but it worked fine, but [hacking / env-setup](https: /) in Installation Procedure on the official website. /github.com/ansible/ansible/blob/devel/hacking/env-setup) adds environment variables to the fullest and it's a little difficult to handle, so I created a virtualenv environment and installed it using setup.py. .. The execution environment is OS X Yosemite + MacPorts. You can replace the virtualenv-2.7 command with 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

It's just a hobby to put awscli at this timing. If you come out to virtualenv with which ansible, it's OK

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

Next, create a profile with awscli.

aws configure --profile toilet

After that, make an appropriate use of local_action and execute it.

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

unko.yml has the following contents.

- 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

I wish I had a little more naming sense.

Recommended Posts

Install ansible from source code
Install Python from source with Ansible
Install python from source
Install Apache 2.4.41 from source
Install PostgreSQL from source code on CentOS
Install Apache Maven (from source)
Install Ansible
Compile and install Git from source.
Install from conda-forge
Flow from source code to creating executable
Install vim7.3 (+ python2.4) from source (compatible with Gundo.vim)
Build PostgreSQL from source
Install Ansible on Mac
[Python] Django Source Code Reading View Starting from Zero ①
Remove one-line comments containing Japanese from source code in Python
Source code character code check script
Stop Omxplayer from Python code
Install pyenv from Homebrew, install Python from pyenv
pip install prevents proxy from installing
Put postfix 2.11 in source with ansible
Code wars kata starting from zero
Execute Python code from C # GUI
Install VS Code on your Chromebook
Run Ansible from Python using API
Migrate from VS Code to PyCharm
[Python] Read the Flask source code
Install and configure `pyenv` Ansible playbook
Get the address from the zip code
Install python with mac vs code
Jinja2 source code formatting using atom-beautify
Count Source lines of code (SLOC)
Install the latest version of Apache httpd 2.4 from source on Cent OS 8