并发与shell

# bruce用户身份,-m指定模块名称,默认模块名command,all所有目标主机,也可以指定组名或者主机名
ansible all -m ping -u bruce # bruce用户身份,sudoing到root用户
ansible all -m ping -u bruce --sudo # bruce用户身份,sudoing到batman用户,-U(--sudo-user)指定sudo用户,-K(--ask-sudo-pass)指定sudo用户密码
ansible all -m ping -u bruce --sudo -U batman # -f指定并发数, command模块不支持变量
ansible atlanta -m command -a '/sbin/reboot' -f 10 # -k指定用户密码,-a模块参数,shell模块支持变量,命令参数必须使用双引号
ansible all -u root -k -m shell -a "/bin/echo $i"

文件传输

# copy模块可以拷贝文件
ansible atlanta -m copy -a 'src=/etc/hosts dest=/tmp/hosts' # file模块可以改变文件属性,建立删除目录文件
ansible webservers -m file -a 'dest=/srv/foo/b.txt mode=600 owner=mdehaan group=mdehaan'
ansible webservers -m file -a 'dest=/path/to/c mode=755 owner=mdehaan group=mdehaan state=directory'
ansible webservers -m file -a 'dest=/path/to/c state=absent'

包管理(yum模块)

ansible webservers -m yum -a 'name=acme state=present' # 确保acme包被安装,但是不升级
ansible webservers -m yum -a 'name=acme-1.5 state=present' # 指定acme包版本号 
ansible webservers -m yum -a 'name=acme state=latest' # acme包升级到最新版本
ansible webservers -m yum -a 'name=acme state=absent' # 确保acme包不被安装

用户&组(user&group模块)

ansible all -m user -a 'name=foo password=<crypted password here>' # 建立用户
ansible all -m user -a 'name=foo state=absent' # 删除用户或者组

版本控制工具(git模块)

ansible webservers -m git -a 'repo=git://foo.example.org/repo.git dest=/srv/myapp version=HEAD'

服务管理(service模块)

ansible webservers -m service -a 'name=httpd state=started' #启动
ansible webservers -m service -a 'name=httpd state=restarted' #重启
ansible webservers -m service -a 'name=httpd state=stopped' #停止

有时限的后台操作

# 后台运行long_running_operation命令,时间为1小时(3600s),系统会给执行同一任务主机一个jid
ansible all -B 3600 -a '/usr/bin/long_running_operation --do-stuff'
# 轮询任务的执行状态
ansible all -m async_status -a 'jid=123456789'
# 后台运行时间1800秒,每60分钟轮询检查一次
ansible all -B 1800 -P 60 -a '/usr/bin/long_running_operation --do-stuff'

系统facts(setup模块)

# 获取目标主机信息
ansible all -m setup

ansible使用2-命令的更多相关文章

  1. Ansible常用模块命令

    Ansible常用模块命令 一.安装ansible yum install epel-release yum install ansible 二.配置文件配置 vi /etc/ansible/ansi ...

  2. Ansible之系列命令详解

    ansible系列命令有:ansible.ansible-doc.ansible-playbook.ansible-vault.ansible-console.ansible-galaxy.ansib ...

  3. ansible 安装 使用 命令 笔记 生成密钥 管控机 被管控机 wget epel源

      ansible 与salt对比 相同 都是为了同时在多台机器上执行相同的命令 都是python开发 不同 agent(saltstack需要安装.ansible不需要) 配置(salt配置麻烦,a ...

  4. ansible的Ad-hoc命令

    本文主要介绍了ansible的Ad-hoc命令. Ansible提供两种方式去完成任务,一是 ad-hoc 命令,一是写 Ansible playbook.前者可以解决一些简单的任务, 后者解决较复杂 ...

  5. paramiko模拟ansible远程执行命令

    主模块 #!/usr/bin/env python from multiprocessing import Process import paramiko import time import sys ...

  6. Ansible 远程执行命令

    写法如下: [root@localhost ~]$ ansible 192.168.119.134 -m command -a 'date' # 对指定的主机远程执行命令,-m 指定使用哪个模块,-a ...

  7. Ansible学习 ad-hoc命令

    Ansible提供两种方式去执行命令,一种是ad-hoc命令,一种是写入Ansible playbook.类似于前者在命令行敲shell,后者是写shell-script脚本,前者解决一些简单的任务, ...

  8. [转] ansible批量执行命令展示

    [From] https://blog.csdn.net/zhydream77/article/details/81223805 ansible命令基础 • ansible <host-patt ...

  9. Ansible 清单与命令解析

    在大规模的配置管理工作中我们需要管理不同业务的不同机器,这些机器的信息都存放在 Ansible 的 Inventory 组件里面,在我们工作中配置部署针对的主机必须先存放在 Invento 组里面,这 ...

  10. ansible使用临时命令通过模块来执行任务

    使用临时命令通过模块来执行任务 一.查看系统上安装的所有模块 ansible-doc -l 查看ping模块帮助文档 ansible-doc ping 1.ansible模块 文件模块: copy:将 ...

随机推荐

  1. Margarite and the best present

    Little girl Margarita is a big fan of competitive programming. She especially loves problems about a ...

  2. 毕业设计 python opencv实现车牌识别 形状定位

    主要代码参考https://blog.csdn.net/wzh191920/article/details/79589506 GitHub:https://github.com/yinghualuow ...

  3. SQL Connect By 的例子

    看到一个较为通俗易懂的connect by的例子,是百度知道的答案,稍微整理了一下.我自己这样理解:connect by prior "id" = "p_id" ...

  4. hdu2553 N皇后问题(dfs+回溯)

    N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. 4 练习: 使用eclipse开发

    1       练习: 使用eclipse开发 1.1  练习目标 本例讲述在使用eclipse如何创建groovy程序. 1.2  创建new Groovy project 本例假设你已经安装好了g ...

  6. angularJs(2)表单中下拉框单选多选

    多选 <input type="checkbox" ng-model='game' ng-true-value="1" ng-false-value=&q ...

  7. SQL SERVER – Configuration Manager – Cannot Connect to WMI Provider. You Do Not Have Permission or The Server is Unreachable

    打开SQL SERVER Configuarion Manger 出现以下错误 SQL Server Configuration Manager—————————Cannot connect to W ...

  8. pod基本操作

    目录 创建Pod 查询Pod 删除Pod 更新Pod @(kernetes虚拟化学习)[pod基本操作] pod基本操作 ---- 创建Pod kubectl create -f test_pod.y ...

  9. Windows 环境下安装MongoDB

    mongoDB下载地址 https://www.mongodb.org/ 在mongoDB官网下载windows版本的mongoDB后解压出来(本文以解压到D盘为例) 在解压出来的MongoDB文件夹 ...

  10. Kafka monitoring监控

    一.Metrics kafka有两个metrics包,在看源码的时候很容易混淆 package kafka.metrics package org.apache.kafka.common.metric ...