ansible的模块介绍

ansible的模块介绍

fetch 将远程机器上的文件拉取到本地,以ip或者主机名生成目录,并保留原来的目录结构

dest  #目标地址
src   #源地址
ansible web -m fetch -a "dest=/tmp src=/var/log/cron"

 

ansible中的yum

ansible web -m copy -a "dest=/etc/yum.repos.d/ src=/etc/yum.repos.d/epel.repo"
1.yum 和rpm的区别
rpm redhat package manage
yum会解决依赖关系
2.yum源的配置
[epel]     # 名称
name=Extra Packages for Enterprise Linux 7 - $basearch   # 描述信息
baseurl=http://mirrors.aliyun.com/epel/7/$basearch  # yum源的地址
failovermethod=priority
enabled=1     # 指定yum源是否可用,1代表可用,0代表不可用
gpgcheck=0    # 是否检查gpgkey文件,0代表不检查,1代表的检查
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
3.包组 #就是一个很多开发软件的集合
linux lib  windows dll  、
rpc 远程过程调用
yum grouplist #查看包组
yum groupinstall "模块名字" # 安装包组
4.查看包安装状态
yum list|grep redis @代表安装成功
rpm -q redis 
rpm -qa 查看所有的包
rpm -ql 查看包安装生成的文件

systemctl start  redis 不占用端口启动项目
ps -ef |grep redis  查看redis的端口
ss -tunlp 

 

ansible中的yum模块: 

disable_gpg_check # 是否要检查key
disablerepo # 禁用repo
enablerepo #启用repo
name # 包名
state # 状态 installed removed
ansible web -m yum -a "name=python2-pip" # 安装一个包
ansible web -m yum -a "name='@Development Tools'" # 安装包组
ansible web -m yum -a "name=redis,python2-pip" # 同时安装多个包
ansible web -m yum -a "name=redis state=absent" # 卸载

  

yum和rpm的区别:

rpm是由红帽公司开发的软件包管理方式,使用rpm我们可以方便的进行软件的安装、查询、卸载、升级等工作。但是rpm软件包之间的依赖性问题往往会很繁琐,尤其是软件由多个rpm包组成时。
Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。

 

ansible中的pip模块

pip list #查看所有的python第三方包
pip freeze > a.txt # 导出
pip install -r a.txt # 安装

  

requirements #导出的文件
name # 包名
virtualenv # 虚拟环境
ansible web -m pip -a "name=django==1.11.18" # 安装
ansible web -m pip -a "name=flask 

  

ansible中的service模块

#centos6和cenos7中的区别

ps -ef|grep redis # 查看进程
ss -tnlp #查看端口信息
# 启动服务
systemctl start redis  centos7
service redis start    centos6
# 开机自启动
systemctl enable redis centos7
chkconfig redis on centos6

  

pip模块的介绍

enabled # 设置开机自启动
name # 名称
state #状态
	started  #启动
	stopped  #关闭
	restarted #
	reloaded  #重新的加载
ansible web -m service -a "name=redis state=started" # 启动
ansible web -m service -a "name=redis state=stopped" # 关闭
ansible web -m service -a "name=redis state=started enabled=yes" # 启动并设置开机自启动

  

ansible中的crontab模块

* * * * * job
分 时 日 月 周 任务
1 * * * * job    # 代表每小时的第一个分钟
2/* * * * * job  # 每隔2分钟执行job
1 10-19 * * * job  # 代表10到19点的第一分钟
0-59 0-23 1-31 1-12  0-7 job
* * * * * tar -zcf /opt/etc.tar.gz /etc
分钟不要用*,最好是指定时间
分钟不要用*,最好是指定时间
分钟不要用*,最好是指定时间
收集日志
备份数据
同步时间
crontab -l # 查看计划任务
crontab -r # 删除所有的计划任务
crontab -e # 编辑计划任务

  

#crontab的介绍

day # 天
hour # 小时
job #任务
minute #分钟
month # 月
name #名字,描述信息,不可以重复
state # 状态
user # 执行计划任务的用户
weekday # 周
disabled # 禁止
ansible web -m cron -a "minute=21 job='touch /tmp/cron.txt' name=touchfile" # 设置计划任务
ansible web -m cron -a "minute=23 job='touch /tmp/cron.txt' name=touchfile4 disabled=yes" # 禁用计划任务,表现为加注释
ansible web -m cron -a "name=touchfile4 state=absent" # 删除计划任务
witch 命令的名字  查看命令的路径

  

ansible中的user模块

用户的分类
超级管理员   root                      0
其他用户  
  系统用户 启动服务来专门设置的用户      1-999 centos7   1-499 centos6
  登陆用户 普通的登陆用户              1000-65535centos7 500-65535 centos6
	
useradd 
-d # 指定家目录
-g # 组id
-G, --groups GROUPS  # 附加组
-r, --system  # 创建系统用户
-s, --shell SHELL # 登陆shell
-u, --uid UID #用户id
useradd -s /sbin/nologin -u 2000 -d /opt/wusir wusir #创建用户,指定用户的登陆shell,id,家目录
useradd -s /sbin/nologin -G root,wusir  -d /opt/wusir2 wusir2 #指定附加组,最大的后面+1
useradd -r baoyuan # 创建系统用户,从999倒序
userdel wusir2 # 删除用户
userdel -r baoyuan4 # 删除用户并删除用户的家目录 
    

  

group # 组
groups #附加组
home #家目录
name #用户名
password #密码
shell #登陆shell
remove # 删除用户并删除用户的家目录
state # 状态
system #系统用户
uid # 用户id
ansible db -m user -a "name=alex2 shell=/sbin/nologin home=/opt/alex2 uid=2000 group=root" # 创建用户,并指定用户的家目录,登陆shell,uid,组
ansible db -m user -a "name=alex3 system=yes" #创建系统用户
ansible db -m user -a "name=alex3 state=absent" # 删除用户
ansible db -m user -a "name=alex2 state=absent remove=yes" # 删除用户并删除用户的家目录

  

ansible中的group模块

用户组的分类
超级组   root                      0
其他组  
  系统组   1-999 centos7   1-499 centos6
  普通组   1000-65535centos7 500-65535 centos6
groupadd 
-g 指定组的id
-r 指定系统组
groupdel 

  

gid #组的id
name # 组名
state #状态
system #系统组
ansible db -m group -a "name=canglaoshi" #创建普通组
ansible db -m group -a "name=wutenglan system=yes" # 创建系统组
ansible db -m group -a "name=wutenglan state=absent" # 删除组

  

  

 

posted @ 2019-04-11 17:46  7411  阅读(154)  评论(0)    收藏  举报