ansible

How to fix “Unreachable” when ping windows with ansible over ssh?

*爱你&永不变心* 提交于 2020-02-07 05:23:29
问题 I'm trying to use Ansible with ssh for interact with Windows machines i have successfully install OpenSSH on a Windows machine that mean i can connect from linux to windows with: ssh username@ipAdresse i've tried using a lot of version of ansible (2.6, 2.7.12, 2.7.14, 2.8.5 and 2.8.6) and i always test if i can ping an other Linux machine with this line(it work): ansible linux -m ping There is my hosts file [windows] 192.***.***.*** [linux] 192.***.***.*** [all:vars] ansible_connection=ssh

Ansible角色管理-Roles(实例演示!!!)

試著忘記壹切 提交于 2020-02-06 16:52:56
Roles的概述 Roles能够根据层次型结构自动装载变量文件、task以及handlers等。 简单来讲,Roles就是通过分别将变量、文件、任务、模块及处理器放置于单独的目录中,并可以便捷地include它们。 Roles一般用于基于主机构建服务的场景中,但也可以用于构建守护进程等场景中。 Roles的目录 目录名称 具体含义 files 用来存放由copy模块或script模块调用的文件 templates 用来存放j正则模板,template模块会自动在此目录中寻找正则模板文件 tasks 此目录应当包含一个main.yml文件,用于定义此角色的任务列表,此文件可以使用include包含其它的位于此目录的task文件 handlers 此目录应当包含一个main.yml文件,用于定义此角色中触发条件时执行的动作 vars 此目录应当包含一个main.yml文件,用于定义此角色用到的变量 defaults 此目录应当包含一个main.yml文件,用于为当前角色设定默认变量 meta 此目录应当包含一个main.yml文件,用于定义此角色的特殊设定及其依赖关系 在playbook中使用Roles的步骤 创建以roles命令的目录 #yum装完默认就有 mkdir /etc/ansible/roles/ -p 创建全局变量目录 mkdir /etc/ansible/group

Set different ORACLE_HOME and PATH environment variable using Ansible

余生颓废 提交于 2020-02-06 08:23:30
问题 Im currently querying multiple databases and capturing the results of the query The way Im doing it is, Im writing a task which copies a shell script, something like below #!/bin/bash source $HOME/bin/gsd_xenv $1 &> /dev/null sqlplus -s <<EOF / as sysdba set heading off select d.name||','||i.instance_name||','||i.host_name||';' from v\$database d,v\$instance i; EOF In the playbook, Im writing the task as below: - name: List Query [Host and DB] shell: "/tmp/sqlscript/sql_select.sh {{item}} >>

ansible异步任务

不羁的心 提交于 2020-02-05 00:12:52
转载于简书博客 https://www.jianshu.com/p/3962bf94ae70 ansible方便在于能批量下发,并返回结果和呈现。简单、高效。 但有的任务执行起来却不那么直接,可能会花比较长的时间,甚至可能会比ssh的超时时间还要长。这种情况任务是不是没法执行了? ansible考虑到了这种情况,官方文档介绍了这个问题的解决方法,就是让下发的任务执行的连接变为异步:任务下发之后,长连接不再保持,而是每隔一段时间轮询结果,直到任务结束。 这是官网相关的介绍 他们在playbook的任务中加入两个参数:async和poll。 async参数值代表了这个任务执行时间的上限值。即任务执行所用时间如果超出这个时间,则认为任务失败。此参数若未设置,则为同步执行。 poll参数值代表了任务异步执行时轮询的时间间隔。 官方给出例子: ---- hosts: all remote_user: root tasks: - name: simulate long running op (15 sec), wait for up to 45 sec, poll every 5 sec command: /bin/sleep 15 async: 45 poll: 5 这时候已经不怕任务超时了。可以执行一个45s的任务,当然也可以根据需要自己设置。另外,如果poll为0

ansible下载文件的多种方式

老子叫甜甜 提交于 2020-02-05 00:06:57
对于ansible来说,下载文件是一个很重要的课题,这是build或者deploy的第一步,通常来讲由于不同项目的差异,可能我们的代码包或者资源文件保存在于http,github,nexus,ftp,nas等等。 http文件下载,前提是http允许匿名用户下载 - name: download war file get_url: url: "{{ https_url }}/start.war" dest: /tmp mode: 0644 force: yes validate_certs: no github 文件下载,前提是已经在github申请了token - name: donwload docker rpm get_url: validate_certs: no url: https://github.com/raw/org_name/project/master/docker.rpm dest: /tmp/docker.rpm mode: 0755 force: yes headers: Authorization: token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 如果想让文件下载到ansible master端,只要增加一条 delegate_to: localhost 一个完整的task,如下: - name:

docker 实践四:仓库管理

一笑奈何 提交于 2020-02-04 20:07:37
本篇我们来了解 docker 仓库的内容。 注:环境为 CentOS7,docker 19.03 仓库(Responsitory)是集中存放镜像的地方,又分公共仓库和私有仓库。 注:有时候容易把仓库与注册服务器(Registry) 混淆。 实际上注册服务器是存放仓库的具体服务器, ⼀个注册服务器上可以有多个仓库, ⽽每个仓库下⾯可以有多个镜像。 公有仓库 Docker Hub 是 docker 官方提供的最大的公共镜像仓库,地址为 https://hub.docker.com 。 登录 可以使用命令 docker login 来注册和登陆。 基本操作 使用命令 docker search [IMAGE] 来搜索镜像: # docker search centos NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official build of CentOS. 5520 [OK] ansible/centos7-ansible Ansible on Centos7 122 [OK] jdeathe/centos-ssh CentOS-6 6.10 x86_64 / CentOS-7 7.6.1810 x86… 111 [OK] 上面显示的镜像分为两类: ⼀种是类似于centos这样的基础镜像, 也称为根镜像。

Docker仓库

雨燕双飞 提交于 2020-02-04 20:06:04
简介   仓库(Repository)是集中存放镜像的地方。   一个容易与之混淆的概念是注册服务器(Registry)。实际上注册服务器是存放仓库的具体服务器,每个服务器上可以有多个仓库,而每个仓库下面有多个镜像。从这方面来说,仓库可以被认为是一个具体的项目或目录。例如对于仓库地址hub.docker.com/_/ubuntu来说,hub.docker.com是注册服务器地址,ubuntu是仓库名。   仓库又分公共仓库和私有仓库,在本文将展示如何使用DockerHub官方仓库进行登录、下载等基本操作;最后还将介绍创建和使用私有仓库的基本操作。 Docker Hub   目前Docker官方维护了一个公共仓库https:/hub.docker.com,其中已经包括15000多个的镜像。大部分需求都可以通过在Docker Hub中直接下载镜像来实现。 登录   可以通过执行docker login命令来输入用户名、密码和邮箱来完成注册和登录。注册成功后,本地用户目录的.dockercfg中将保存用户的认证信息。 基本操作   用户无需登录即可通过docker search命令来查找官方仓库中的镜像,并利用docker pull命令来将它下载到本地。   在前面博文中,已经具体介绍了如何使用docker pull命令。例如以centos为关键词进行搜索: [root@gavin ~]

Ansible playbook - environment variables

老子叫甜甜 提交于 2020-02-04 01:45:27
问题 I am trying (newbie) to setup a playbook, which will use lookup plugin to fetch secrets from vault (https://github.com/jhaals/ansible-vault), but it will fail on missing environment variables every time. Can anyone help? Thanks for the help. PS: token is for a test purposes There is condition in lookup module : url = os.getenv('VAULT_ADDR') if not url: raise AnsibleError('VAULT_ADDR environment variable is missing') Playbook: --- - hosts: localhost vars: vault1_env: VAULT_ADDR: https:/

Ansible playbook - environment variables

落花浮王杯 提交于 2020-02-04 01:45:09
问题 I am trying (newbie) to setup a playbook, which will use lookup plugin to fetch secrets from vault (https://github.com/jhaals/ansible-vault), but it will fail on missing environment variables every time. Can anyone help? Thanks for the help. PS: token is for a test purposes There is condition in lookup module : url = os.getenv('VAULT_ADDR') if not url: raise AnsibleError('VAULT_ADDR environment variable is missing') Playbook: --- - hosts: localhost vars: vault1_env: VAULT_ADDR: https:/

Ansible剧本管理(实例解释!!!)

纵然是瞬间 提交于 2020-02-03 23:12:04
inventory主机清单 ansible默认的主机清单是/etc/ansible/hosts文件,主机清单可以手动设置,也可以通过Dynamic Inventory动态生成,一般主机名使用FQDN vim /etc/ansible/hosts [webserver] #方括号设置组名 www1.example.org #定义被监控主机,这边可以是主机名也可以是IP地址,主机名需要修改/etc/hosts文件 www2.example.org:2222 #冒号后定义远程连接端口,默认是ssh的22端口 如果是名称类似的主机,可以使用列表的方式标识各个主机 [webserver] www[01:50].example.org ansible_ssh_user=root ansible_ssh_pass=123456 [dbbservers] db-[a:f].example.org inventory变量 主机变量 [webserver] www1.magedu.com http_port=80 maxRequestsChild=808 www2.magedu.com http_port=8080 maxRequestsChild=909 组变量 [servers:vars] ntp_server=ntp.example.org nfs_server=nfs.example.org