首页 > 其他分享 >1. ansible学习总结: 基础模块

1. ansible学习总结: 基础模块

时间:2022-12-17 18:44:18浏览次数:42  
标签:总结 httpd name kingdee ansible hosts 模块 become

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_distribution_major_version 操作系统版本
"ansible_machine" 操作系统架构
"ansible_hostname" 主机名称
"ansible_default_ipv4" ipv4地址
"ansible_all_ipv4_addresses" ipv4地址
"ansible_processor_cores": cpu核数
"ansible_memory_mb" 内存使用情况
#查找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

 

标签:总结,httpd,name,kingdee,ansible,hosts,模块,become
From: https://www.cnblogs.com/liyuzhoupan/p/16989339.html

相关文章

  • 2022年年终总结
    主要分成四大块来进行总结做了啥?没做啥?感受?明年想做啥?做了啥【按时间线】?1、跟随公司发布了新版本的软件2、跳槽涨薪3、参加了钢琴比赛4、0到1实现新项目......
  • 计算机算法设计与分析第一章总结
    1.1算法与程序算法是解决问题的一种方法或一个过程。严格地说,算法是由若干条指令组成的有穷序列,且满足下述4条性质。输入输出:至少产生一个量作为输出。确定性:每条指......
  • ansible-play 使用yum模块批量安装多个软件包,
      ----hosts:bbtasks:-yum:name={{item}}state=installedwith_items:-yum-utils-bash-completion-vim......
  • C# Log4net配置文件 总结
    前言因为项目日志太杂乱而且很大,打开一个就卡死了,何况用户电脑也扛不住日志积累,要做一个日志记录器管理日志。但对里面的配置有一些不熟悉(毕竟都是复制粘贴的),所以记录一......
  • 串口接收模块——verilog实现
    1、设计想法原理与之前的串口发送模块一样,1位的数据位和8位的数据位再加上1位的停止位。唯一不同的是在接收的时候要考虑到有干扰的情况下,为了避免干扰,我们对每位数据进行......
  • 汉字编码与编程相关问题总结:ASCII、机内码、区位码、国标码、Unicode码是如何转换的
    一、ASCII、机内码、区位码、国标码、Unicode码他们之间是如何转换的,方程式是什么汉字系统中的过程包括区位码、国标码和机内码,其中的转换关系如下:1.区位码(十进制)转......
  • 大数据Hadoop之——总结篇
    目录一、前言二、Hadoop1)HDFS常见操作1、HDFS服务启停命令2、常见文件操作命令3、安全模式操作命令4、数据平衡常见操作命令5、处理小文件常见操作命令6、HDFSNameNode主......
  • iOS 开发:『Blocks』详尽总结 (二)底层原理
     本文用来介绍iOS开发中『Blocks』的底层原理。我将通过Blocks由OC转变的C++源码来一步步解析Blocks的底层原理。通过本文您将了解到:Blocks的实质是......
  • PYTHON 模块 - random
    1.1random模块用于生成随机数。1.2相关方法random.random()用于生成一个0到1的随机浮点数:0<=n<1.0>>>importrandom>>>random.random()0.6067277881757......
  • PYTHON 模块
    1.1模块模块是一个包含所有你定义的函数和变量的文件,其后缀名是.py。模块可以被别的程序引入,以使用该模块中的函数等功能。1.2导入模块import模块1,模块2,...定......