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 ~]#

后面太深了!!!!!

ansible+docker的更多相关文章

  1. jenkins + ansible + docker 代码集成发布

    一.环境搭建 1. 安装Java 配java_home, /etc/profile 2.安装Jenkins 下载war包,用 Java -jar  Jenkins.war或者  把war包放tomca ...

  2. Fbric、Ansible、Docker、Chaos Monkey:DevOps工具的年中回顾

    Fbric.Ansible.Docker.Chaos Monkey:DevOps工具的年中回顾 [编者按]近日,Cyber Engineering Solutions Group 技术经理 Hasan ...

  3. Ansible快速上手

    ansible 是通过python 语言开发的自动化运维工具,可以实现批量系统设置.批量程序部署.批量执行命令等功能 下面是基于docker使用ansible测试示例,可以让新手快速上手使用 一.新建 ...

  4. 基于 Docker 的微服务架构实践

    本文来自作者 未闻 在 GitChat 分享的{基于 Docker 的微服务架构实践} 前言 基于 Docker 的容器技术是在2015年的时候开始接触的,两年多的时间,作为一名 Docker 的 D ...

  5. ansible基本使用方法

    一.ansible的运行流程 ansible是基于ssh模块的软件,所以主控端和被控端的ssh服务必须正常才能保证ansbile软件的可用性. 检查ssh服务是否正常:   systemctl sta ...

  6. docker HealthCheck健康检查

    需求 最近遇到的问题:线上跑的一个 Node 镜像是在运行的,状态为 up ,但是访问报 502 ,重启镜像无效,重新拉了个镜像运行才恢复正常.于是想研究下如何从应用层面去检查容器的状态 为什么 do ...

  7. 《Docker从入门到跑路》之基本用法介绍

    Docker是一种轻量级的虚拟化技术,它具备传统虚拟机无法比拟的优势,它更简易的安装和使用方式.更快的速度.服务集成和开源流程自动化. Docker的安装 安装Docker的基本要素:1.Docker ...

  8. k8s之ansible安装

    项目地址:https://github.com/easzlab/kubeasz #:先配置harbor #:利用脚本安装docker root@k8s-harbor1:~# vim docker_in ...

  9. 【Ansible】ansible容器学习环境搭建

    想要学习ansible,只有一个节点肯定是不行的,而搭建虚拟机又是一件非常费时费力费资源的事情,所以通过docker 快速搭建一个容器学习环境是一个不错的选择 1. 了解ansible部署 1.1 需 ...

随机推荐

  1. javascript对象转为字符串

    function getStringTime(time){ //年 year = time.getFullYear(); //月 month = time.getMonth() if(String(m ...

  2. FreeRTOS软件定时器的使用

    先贴上一个创建的代码,先声明一个句柄 TimerHandle_t pump_wakeup_timer_handle = NULL; 创建定时器和启动定时器,第三个参数,pdFALSE是只定时一次,pd ...

  3. springmvc基础篇—使用注解方式为前台提供数据

    一.新建一个Controller package cn.cfs.springmvc.service; import java.util.ArrayList; import java.util.Hash ...

  4. PHP将两个数组相加

    $arr_a=[1=>1,2=>2,3=>3];$arr_b=[1=>'a',4=>4];print_r($arr_a+$arr_b);返回结果:Array ( [1] ...

  5. Struts2(五.用户注册的实现及整合Action的配置方法)

    一.用户注册功能 register.jsp页面 若是jquery ajax方式提交给action,还要回到jquery,控制权在jquery若是表单方式提交给action,控制权交给action &l ...

  6. 利用devcon工具编写bat脚本一键控制系统设备,如开启关闭网卡

    系统WIN7 x64位 下载devcon命令行工具 Download the "Windows Driver Kit (WDK) 7.1.0 from Microsoft: http://w ...

  7. 安装配置hadoop

    在master中安装并且配置hadoop (1).将hadoop-2.6.4.tar.gz安装包复制到hadoop文件目录下(直接赋值进去就行) (2).解压安装包haoddp-2.6.4.tar.g ...

  8. c++调用Python基础功能

    c++调用Python首先安装Python,以win7为例,Python路径为:c:\Python35\,通过mingw编译c++代码.编写makefile文件,首先要添加包含路径:inc_path ...

  9. Linux 简单socket实现UDP通信

    服务器端 #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sy ...

  10. 数据结构14——AC自动机

    一.相关介绍 知识要求 字典树Trie KMP算法 AC自动机 多模式串的字符匹配算法(KMP是单模式串的字符匹配算法) 单模式串问题&多模式串问题 单模就是给你一个模式串,问你这个模式串是否 ...