Ansible Tryout

下载镜像,容器运行

docker pull ansible/centos7-ansible
docker run -it --rm ansible/centos7-ansible -e ANSIBLE_HOST_KEY_CHECKING=false /bin/bash

由于要用到ssh密码登录,需要install sshpasss

yum -y install sshpass.x86_64

编辑/etc/ansible/hosts,定义机器inventory

[mygroup]
machine1 ansible_ssh_host=10.196.128.11 ansible_ssh_port=36000 ansible_ssh_user=user
machine2 ansible_ssh_host=10.196.128.12 ansible_ssh_port=36000 ansible_ssh_user=user

通过ansible运行ad-hoc command

ANSIBLE_HOST_KEY_CHECKING=false ansible gate -m 'ping' --ask-pass 
SSH password: 
    gate1 | success >> {
        "changed": false, 
        "ping": "pong"
    }

    gate2 | success >> {
        "changed": false, 
        "ping": "pong"
    }

通过ansible运行ad-hoc command

ANSIBLE_HOST_KEY_CHECKING=false ansible gate -a 'date' --ask-pass     
    SSH password: 
    gate1 | success | rc=0 >>
    Tue Mar 10 16:31:38 CST 2015

    gate2 | success | rc=0 >>
    Tue Mar 10 16:31:38 CST 2015

编辑一个Playbook,执行docker container

---

- hosts: gate
  remote_user: gaia
  vars:
    image_name: docker.oa.com:8080/gaia/gate:v0.8-hub
    container_name: portalGate
    gate_home: ~/gaia_portal/portal_gate-1.0
  tasks:
  - name: pull gate image
    command: docker pull {{ image_name }}
  - name: remove old container
    command: docker rm -f {{ container_name }}
    ignore_errors: True
  - name: start new container
    command: docker run --name {{ container_name }} -d -p 8085:8080 
             -v {{ gate_home }}/docker-log:/app/log 
             {{ image_name }}

编辑一个Playbook,执行long-running process

---

- hosts: test
  remote_user: gaia
  vars:
    apiserver_home: ~/gaia_portal/portal_api_server-1.0
  tasks:
  - name: start new process
    command: chdir="{{ apiserver_home }}" "{{ apiserver_home }}/bin/run.sh"
    async: 31536000
    poll: 0

运行Playbook, parallelism=2

ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook gate-start.yaml -f 2 --ask-pass

你可能感兴趣的:(Distributed,System)