wynemo
12/23/2016 - 6:39 AM

ansible_learning.sh http://docs.ansible.com/ansible/intro.html

---
- hosts: "{{ hosts }}"

  tasks:
  - name: create cache, env directory
    file: path="{{ item }}" state=directory
    with_items:
      - "{{ cache_dir }}"
      - "{{ env_dir }}"
  - name: Install the package "readline bz2 xz"
    apt:
      name: "{{ item }}"
      state: present
    with_items:
      - libreadline6-dev
      - libbz2-dev
      - xz-utils
      - make
      - gcc
      - libssl-dev
      - zlib1g-dev
    become: yes
    become_method: sudo
  - name: download virtualenv with check (md5)
    get_url:
      url: https://pypi.python.org/packages/d4/0c/9840c08189e030873387a73b90ada981885010dd9aea134d6de30cd24cb8/virtualenv-15.1.0.tar.gz
      dest: "{{ cache_dir }}/virtualenv-15.1.0.tar.gz"
      checksum: md5:44e19f4134906fe2d75124427dc9b716
  - name: download python source with check (md5)
    get_url:
      url: https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
      dest: "{{ cache_dir }}/Python-2.7.13.tar.xz"
      checksum: md5:53b43534153bb2a0363f08bae8b9d990
  - name: unarchive python source
    unarchive:
      src: "{{ cache_dir }}/Python-2.7.13.tar.xz"
      dest: "{{ env_dir }}"
      remote_src: True
      creates: "{{ env_dir }}/Python-2.7.13"
  - name: unarchive virtualenv
    unarchive:
      src: "{{ cache_dir }}/virtualenv-15.1.0.tar.gz"
      dest: "{{ env_dir }}"
      remote_src: True
      creates: "{{ env_dir }}/virtualenv-15.1.0"
  - name: configure python
    command: ./configure --prefix={{ env_dir }}/python2.7
    args:
      chdir: "{{ env_dir }}/Python-2.7.13"
      creates: "{{ env_dir }}/Python-2.7.13/Makefile"
  - make:
      chdir: "{{ env_dir }}/Python-2.7.13"
  - make:
      chdir: "{{ env_dir }}/Python-2.7.13"
      target: install
  - name: install virtualenv
    command: "python2.7/bin/python virtualenv-15.1.0/virtualenv.py --never-download env"
    args:
      creates: "{{ env_dir }}/env"
      chdir: "{{ env_dir }}"
# http://docs.ansible.com/ansible/intro.html
####################################################
# create env

cd somedir
export PATH=$PATH:$PWD/env/bin

wget -c https://pypi.python.org/packages/d4/0c/9840c08189e030873387a73b90ada981885010dd9aea134d6de30cd24cb8/virtualenv-15.1.0.tar.gz
wget -c https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
cd Python-2.7.13
mkdir $PWD/../python2.7
./configure --prefix=$PWD/../python2.7

#sudo aptitude install libbz2-dev # bip2 is necessary, to install some python packages
#libreadline6-dev

#sudo yum install readline-devel
#sudo yum install bzip2-devel

make  
make install # you have to install it 
cd ..
python2.7/bin/python virtualenv-15.1.0/virtualenv.py --never-download env

############ create env end
######################################################################3333

mkdir ~/.download # cache dir

env/bin/pip wheel --wheel-dir=~/.download/ --find-links=~/.download/ pip
env/bin/pip install --use-wheel --no-index --find-links=~/.download/ --upgrade pip
env/bin/pip wheel --wheel-dir=~/.download/ --find-links=~/.download/ ansible
env/bin/pip install --use-wheel --no-index --find-links=~/.download/ --upgrade ansible

sudo mkdir /etc/ansible/

#zdb@dabin:~/ansible$ cat ~/.ssh/config
#Host dabin.info
#    User zdb
#    Port 233
#    IdentityFile ~/.ssh/dabininfo
#Host jp.dabin.info
#    User zdb
#    Port 233
#    IdentityFile ~/.ssh/jpdabininfo

#zdb@dabin:~/ansible$ cat /etc/ansible/hosts
#dabin.info
#jp.dabin.info

ansible dabin.info -m ping
ansible all -m ping --sudo #sudo
ansible all -m ping --sudo
ansible all -a "/bin/echo hello"

ansible all -a "aptitude install -y git" --sudo # install git

ansible all -a "/bin/bash -c 'ps aux|grep -v ansible|sort -nk 4|tail'" # check system mem usage
ansible all -m shell -a "ps aux|grep -v ansible|sort -nk 4|tail" # or use shell

# http://docs.ansible.com/ansible/playbooks_intro.html
ansible-playbook env.yml --extra-vars "hosts=jp.dabin.info"  #run playbook
ansible jp.dabin.info -m shell -a "ls -la ~/"

ansible-playbook env.yml --extra-vars "hosts=jp.dabin.info cache_dir=~/.download env_dir=/home/zdb/ansible1"