copy模块
#传输文件到目标机
ansible -i /kingdee/ansible/host all -m copy -a 'src=/tmp/aaaa.tgz dest=/tmp/aaaa.tgz'

cron模块:
#创建任务
ansible -i /kingdee/ansible/host all -m cron -a 'hour=2 minute=20 weekday=1-5 name="backup_mysql" job=/root/mysql_backup'
ansible -i /kingdee/ansible/hosts all -m cron -a "hour=2 minute=*/5 weekday=1-5 name="Sycntime" job='/usr/bin/ntpdate 88.888.88.88 &>/dev/null' "

#禁用计划
ansible -i /kingdee/ansible/hosts all -m cron -a " job='/usr/bin/ntpdate 88.888.88.88 &>/dev/null' disabled=yes"

#启用计划任务
ansible -i /kingdee/ansible/hosts all -m cron -a " job='/usr/bin/ntpdate 88.888.88.88 &>/dev/null' disabled=no"

#删除计划任务
ansible -i /kingdee/ansible/hosts all -m cron -a " job='/usr/bin/ntpdate 88.888.88.88 &>/dev/null' name="Sycntime" state=absent"

yum模块,只支持centos:
#安装
ansible -i /kingdee/ansible/hosts all -m yum -a "name=net-tools state=latest" -become
ansible -i /kingdee/ansible/hosts all -m yum -a "name=httpd" -become
#卸载
ansible -i /kingdee/ansible/hosts all -m yum -a "name=net-tools state=absent" -become
ansible -i /kingdee/ansible/hosts all -m yum -a "name=httpd state=absent" -become
#指定下载源,安装多个组件,包括版本
ansible -i /kingdee/ansible/hosts all -m yum -a "name=net-tools,nginx,mysql,git-1.8.3.1-23.el7_8.x86_64 state=latest enablerepo=local" -become

service模块:
#启动httpd
ansible -i /kingdee/ansible/hosts all -m service -a "name=httpd state=started" -become
#停止httpd
ansible -i /kingdee/ansible/hosts all -m service -a "name=httpd state=stopped" -become
#开机启动httpd
ansible -i /kingdee/ansible/hosts all -m service -a "name=httpd enabled=yes" -become
#开机启动取消httpd
ansible -i /kingdee/ansible/hosts all -m service -a "name=httpd enabled=no" -become
#重新加载配置文件
ansible -i /kingdee/ansible/hosts all -m service -a "name=httpd daemon_reload=yes " -become

group模块:
#创建组:
ansible -i /kingdee/ansible/hosts all -m group -a "name=httpd gid=1001 system=yes" -become
#删除组
ansible -i /kingdee/ansible/hosts all -m group -a "name=httpd gid=1001 state=absent" -become

user模块:
#创建用户create_home是否创建home目录,home路径
ansible -i /kingdee/ansible/hosts all -m user -a "name=testadmin comment='test_uer' uid=1001 groups=1001 shell=/sbin/nologin system=yes create_home=yes home=/home/test_user" -become

#删除用户,remove=yes删除用户home目录
ansible -i /kingdee/ansible/hosts all -m user -a "name=testadmin state=absent remove=yes" -become

lineinfile模块:操作都是行,注意不是特定字段
#创建testfile.txt文件行
ansible -i /kingdee/ansible/hosts all -m shell -a "echo 'aaaaaa123asdf' > /kingdee/testfile.txt" -become
#替换testfile.txt中的内容aaaaaa
ansible -i /kingdee/ansible/hosts all -m lineinfile -a "path=/kingdee/testfile.txt regexp='aaaaaaa' line='bbbbbb'" -become
#删除已#号开头的行
ansible -i /kingdee/ansible/hosts all -m lineinfile -a "path=/kingdee/testfile.txt regexp='^#' state=absent'" -become


replace模块:替换文件夹中的内容
ansible -i /kingdee/ansible/hosts all -m replace -a "path=/kingdee/testfile.txt regexp='bbbbbb' replace='asdf123123134523452'" -become

setup模块:手机远程主机信息

ansible_all_ipv4_addresses:仅显示ipv4的信息。
ansible_devices:仅显示磁盘设备信息。
ansible_distribution:显示是什么系统,例:centos,suse等。
ansible_distribution_major_version:显示是系统主版本。
ansible_distribution_version:仅显示系统版本。
ansible_machine:显示系统类型,例:32位,还是64位。
ansible_eth0:仅显示eth0的信息。
ansible_hostname:仅显示主机名。
ansible_kernel:仅显示内核版本。
ansible_lvm:显示lvm相关信息。
ansible_memtotal_mb:显示系统总内存。
ansible_memfree_mb:显示可用系统内存。
ansible_memory_mb:详细显示内存情况。
ansible_swaptotal_mb:显示总的swap内存。
ansible_swapfree_mb:显示swap内存的可用内存。
ansible_mounts:显示系统磁盘挂载情况。
ansible_processor:显示cpu个数(具体显示每个cpu的型号)。
ansible_processor_vcpus:显示cpu个数(只显示总的个数)。

#查找IP地址,使用filter进行过滤,可以采用通配符查找
ansible -i /kingdee/ansible/hosts all -m setup -a "filter=*ipv4_addresses*"
#查找版本
ansible -i /kingdee/ansible/hosts all -m setup -a "filter=ansible_distribution_major_version"
#为减少每次执行ansile都需要收集setup,效率比较低,可以增加gather_facts:no来禁止手机facts

1. ansible学习总结: 基础模块的更多相关文章

  1. ansible中文手册-基础模块使用

    此篇文章主要是翻译ansible官网文档而来,在里面讲述了如何使用ansible的基础模块,总体感觉比较晦涩,但是后面会写出自己相关实践的文档,从而更加通俗易懂,官网的东西拿来当手册偶尔翻翻也是很不错 ...

  2. mage Ansible学习1 常用模块

    一.Ansible特点 二.Ansible架构 1.core modules实现常用模块 2.Custom modules实现自定义模块 3.Connection Plugins 连接插件,可通过SS ...

  3. ansible学习系列2-ansible常用模块使用

    1. 查看支持的模块 [root@localhost ~]# ansible-doc -l 这里我们看下ansible的支持的模块个数 [root@localhost ~]# ansible-doc ...

  4. Node.js实战项目学习系列(5) node基础模块 path

    前言 前面已经学习了很多跟Node相关的知识,譬如开发环境.CommonJs,那么从现在开始要正式学习node的基本模块了,开始node编程之旅了. path path 模块提供用于处理文件路径和目录 ...

  5. Ansible学习分享(基本)

    背景:Teamleader提到一款好用的自动化配置管理工具,于是前去学习实践,有了下面分享. 纲要 一.Ansible简介 二.Ansible准备 2.1 Ansible安装 2.2 设置SSH公钥验 ...

  6. Ansible简介及常用模块

    一.基础介绍 1.简介 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置. ...

  7. node.js基础模块http、网页分析工具cherrio实现爬虫

    node.js基础模块http.网页分析工具cherrio实现爬虫 一.前言      说是爬虫初探,其实并没有用到爬虫相关第三方类库,主要用了node.js基础模块http.网页分析工具cherri ...

  8. ansible 学习与实践

    title: ansible 学习与实践 date: 2016-05-06 16:17:28 tags: --- ansible 学习与实践 一 介绍 ansible是新出现的运维工具是基于Pytho ...

  9. Python学习笔记基础篇——总览

    Python初识与简介[开篇] Python学习笔记——基础篇[第一周]——变量与赋值.用户交互.条件判断.循环控制.数据类型.文本操作 Python学习笔记——基础篇[第二周]——解释器.字符串.列 ...

  10. Ansible学习总结(1)

    ---恢复内容开始--- 1. Ansible概述 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric) ...

随机推荐

  1. 一个通用的 java 项目的模板

    #!groovy def oper_checkout(SCM_TYPE,SCM_URL,SCM_AUTH_PASS,SCM_BRANCH=' ',SCM_AUTH_USER=' '){ if (SCM ...

  2. excel空格处理

    private String StringTrim(String str){ return str.replaceAll("[\\s\\u00A0]+","") ...

  3. 和ChatGPT聊了一会天它的学习反映能力惊呆了我

    我:用java写一段玫瑰花 ChatGPT:您可以使用 Java 绘制玫瑰花.以下是一段代码: import java.awt.*; import javax.swing.*; public clas ...

  4. Nginx03 虚拟主机

    1 虚拟主机 虚拟主机使用特殊的软硬件技术,把一台运行在因特网上的服务器主机分成一台台"虚拟"的主机,每一台虚拟主机都具有独立的域名,具有完整的Internet服务器(WWW.FT ...

  5. UEFI引导安装UBUNUT

    1.引导方式一定要选UEFI,否则一些显卡驱动将不能安装 2.安装的时候,要在第四个界面,也就是选择覆盖安装还是保留双系统的那个界面,选择其他,一定要自己分区 3.分区: 4.一共5个重要分区: 1. ...

  6. 利用Git+GitHub进行团队协作开发

    自己之前写过两篇关于Git和GItHub使用的文章,分别是 浅谈使用git 进行版本控制博客链接:https://www.cnblogs.com/wj-1314/p/7992543.html 使用Gi ...

  7. Spring(认识、IOC的开发过程、创建bean的方式)

    spring框架(spring全家桶) spring FrameWork springBoot+springCloud+springCloud Data Flow 一:spring的两大核心机制: I ...

  8. Spring框架-AOP核心

    Spring AOP AOP (Aspect Oriented Programming) 面向切面编程 OOP(Object Oriented Programming)面向对象编程,用对象的思想来完善 ...

  9. jenkins简单安装及配置(Windows环境

    jenkins简单安装及配置(Windows环境) jenkins是一款跨平台的持续集成和持续交付.基于Java开发的开源软件,提供任务构建.持续集成监控的功能,可以使开发测试人员更方便的构建软件项目 ...

  10. JZOJ 3432. 【GDOI2014模拟】服务器

    题目 解析 很容易想到的 \(dp\): 设 \(f_i\) 表示已经处理完 \(1..i\) 并且 \(i\) 是直接复制的需要的最小花费 那么 \(f_i=f_j+(i-j) \times (i- ...