zoukankan      html  css  js  c++  java
  • ansible+docker

    1.准备镜像:

    1007 docker run -itd --name client2 ff37bc5ab732
    1008 docker run -itd --name client ff37bc5ab732
    1009 docker run -itd --name client1 ff37bc5ab732
    1010 docker run -itd --name ansible ff37bc5ab732
    1011 docker exec -it ansible /bin/bash

    2.容器ansible安装:

    yum --enablerepo=epel -y install ansible openssh-clients

    mv /etc/ansible/hosts /etc/ansible/hosts.org 
    [root@784390b5dd19 /]# cat /etc/ansible/hosts

    ## db-[99:101]-node.example.com

    # write clients you manage
    172.17.0.2

    # possible to group
    # define any group name you like
    [target_servers]
    # write clients to be grouped
    172.17.0.2
    172.17.0.3
    172.17.0.4
    172.17.0.5

    3.客户端安装SSH-Agent.:简单两步完成:

    ansible:
    ssh-keygen -t rsa
    ssh  172.17.0.5 mkdir -p .ssh
    cat .ssh/id_rsa.pub | ssh 172.17.0.5 'cat >> .ssh/authorized_keys'
    ssh 172.17.0.5测试一下,秒过:
    4.ansible安装成功:

    [root@784390b5dd19 /]# ansible target_servers -m ping
    172.17.0.5 | SUCCESS => {
    "changed": false,
    "ping": "pong"
    }
    172.17.0.4 | SUCCESS => {
    "changed": false,
    "ping": "pong"
    }
    172.17.0.3 | SUCCESS => {
    "changed": false,
    "ping": "pong"
    }
    172.17.0.2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
    }
    [root@784390b5dd19 /]#

    [root@784390b5dd19 /]# ansible target_servers -k -m command -a "uptime"
    SSH password:
    172.17.0.5 | SUCCESS | rc=0 >>
    07:07:33 up 22:13, 1 user, load average: 0.40, 0.12, 0.07

    172.17.0.2 | SUCCESS | rc=0 >>
    07:07:34 up 22:13, 1 user, load average: 0.40, 0.12, 0.07

    172.17.0.3 | SUCCESS | rc=0 >>
    07:07:34 up 22:13, 1 user, load average: 0.40, 0.12, 0.07

    172.17.0.4 | SUCCESS | rc=0 >>
    07:07:34 up 22:13, 1 user, load average: 0.40, 0.12, 0.07

    [root@784390b5dd19 /]#

    5.当然是玩ansible playbook:
    格式要注意!!!
    5.1:
    cat playbook_sample.yml 

    - hosts: target_servers
    tasks:
    - name: jt
    file: path=/home/jt.conf state=touch mode=0600

     运行:ansible-playbook playbook_sample1.yml

     

    好了基本可以了,现在练习,当然一切都是容器,越来越喜欢docker了:playbook

    5.2.

    [root@784390b5dd19 ~]# cat playbook_sample1.yml
    - hosts: target_servers
    tasks:
    - name: httpd is installed
    yum: name=httpd state=installed
    - name: httpd is running and enabled
    service: name=httpd state=started enabled=yes

    5.3

    [root@784390b5dd19 ~]# cat playbook_sample2.yml
    - hosts: target_servers
    tasks:
    - name: General packages are installed
    yum: name={{ item }} state=installed
    with_items:
    - vim-enhanced
    - wget
    - unzip
    tags: General_Packages
    [root@784390b5dd19 ~]#

    5.4使用变量:

    [root@784390b5dd19 ~]# cat playbook_sample3.yml
    - hosts: target_servers
    tasks:
    - name: Refer to Gathering Facts
    command: echo "{{ ansible_distribution }} {{ ansible_distribution_version }} {{ ansible_memory_mb }}"
    register: dist
    - debug: msg="{{ dist.stdout }}"
    [root@784390b5dd19 ~]#

    5.5.

    [root@784390b5dd19 ~]# cat playbook_sample4.yml
    - hosts: target_servers
    tasks:
    - name: index file exists or not
    shell: test -f /var/www/html/index.html
    ignore_errors: true
    register: file_exists
    failed_when: file_exists.rc not in [0, 1]

    - name: put index.html
    shell: echo "httpd index" > /var/www/html/index.html
    when: file_exists.rc == 1

    [root@784390b5dd19 ~]#

    后面太深了!!!!!

  • 相关阅读:
    微信小程序授权获取用户详细信息openid
    微信开发之微信网页授权 完整示例
    linux 安装MySql 5.7.20 操作步骤【亲测】
    CentOS7下rabbitmq的详细安装教程
    Makefile:248: /usr/local/otp_src_18.1/make/x86_64-unknown-linux-gnu/otp_ded.mk: No such file
    Calendar的add()方法介绍
    怎样梳理属于自己的项目管理套路?
    项目经理必备9大获得领导支持秘技
    为什么绝大多数项目经理在不断救火?
    Java IO流学习总结
  • 原文地址:https://www.cnblogs.com/Jt00/p/6971331.html
Copyright © 2011-2022 走看看