回顾:
Ansible:
无需客户端程序
只要有SSH
模块化

ansible帮助工具
ansible-doc 模块名
ansible-doc 模块名 -s 列出该模块的所有选项
ansible-doc -l 列出所有模块

6.group组模块

- gid
设置组id
= name
需要管理的组名
- state
执行状态,absent 删除
present 创建(默认) 例1:创建组名www,并设置gid为666
[root@m01 ~]# ansible oldboy -m group -a "name=www gid=666" 例2:修改ww组的gid为888
[root@m01 ~]# ansible oldboy -m group -a "name=www gid=888" 例3:删除www组
[root@m01 ~]# ansible oldboy -m group -a "name=www gid=888 state=absent"

7.user用户模块

= name
用户名
- uid
uid
- group
gid或groupname
- state
执行状态,absent 删除
present 创建(默认)
- shell
登录shell,/bin/bash(默认),/sbin/nologin
- create_home
创建用户时,是否创建家目录
- password
用户密码,不能使用明文,需要使用openssl加密后的密码
例1:创建一个用户oldboy,指定uid ,gid ,并设置密码为123
注意:password不能使用明文,需要加密,password的加密值需使用双引号
# -1使用MD5进行加密 -stdin 非交互式
[root@m01 ~]# echo "" | openssl passwd - -stdin
$$ByoqasKh$lGSK41WgqAYJ/Ha9K3Yd00
[root@m01 ~]# ansible oldboy -m user -a 'name=oldboy uid=6000 group=666 password="$1$ByoqasKh$lGSK41WgqAYJ/Ha9K3Yd00"' 例2:创建一个程序用户www,指定uid666 gid666 不让登录 不创建家目录
[root@m01 ~]# ansible oldboy -m user -a "name=www uid=666 group=www create_home=no shell=/sbin/nologin

8.file模块

= path
目标文件路径
copy模块的dest
其他模块的name
- src
源文件路径
- owner
属主
- group
属组
- mode
权限
- state
absent 删除
directory 创建目录
file 修改文件属性(默认)
touch 创建文件
link hard 链接
- recurse
递归
recurse=yes
例1:创建目录/data和/backup,属主666,属组666
[root@m01 ~]# ansible oldboy -m file -a "path=/data owner=666 group=666 recurse=yes state=directory"
[root@m01 ~]# ansible oldboy -m file -a "path=/backup owner=666 group=666 recurse=yes state=directory" 例2:创建文件/etc/rsync.passwd,权限600
[root@m01 ~]# ansible oldboy -m file -a "path=/etc/rsync.passwd mode=600 state=touch" 例3:对/etc/hosts做个软链接到/tmp/hosts
[root@m01 ~]# ansible oldboy -m file -a "src=/etc/hosts path=/tmp/hosts state=link" 总结:file模块仅适合创建目录,修改所属和权限,创建链接;除开这些操作的其他文件管理都通过copy模块实现

9.mount挂载模块

= path
挂载点
- src
需要挂载的设备
- fstype
挂在设备的文件系统
iso9660 光驱
ext4
xfs
nfs
cifs samba的共享文件系统
ntfs windows磁盘文件系统
- opts
挂载属性
noatime
noexec
nosuid
= state
挂载动作
present # 开机挂载,仅将挂载配置写入/etc/fstab
mounted # 挂载设备,并将配置写入/etc/fstab
unmounted # 卸载设备,不会清除/etc/fstab写入的配置
absent # 卸载设备,会清理/etc/fstab写入的配置

例1:通过nfs实现网络文件共享

)安装nfs
ansible nfs -m yum -a "name=nfs-utils state=installed"
)启动服务
ansible nfs -m service -a "name=rpcbind state=started"
ansible nfs -m service -a "name=nfs state=started"
)修改配置文件
方法一:在m01上创建配置文件,然后通过copy模块推送给nfs(建议使用)
mkdir -p /server/conf
echo '/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)' > /server/conf/exports
ansible nfs -m copy -a 'src=/server/conf/exports dest=/etc/'
方法二:在m01上直接使用copy模块,推送文件内容
ansible nfs -m copy -a 'content="/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)" dest=/etc/exports'
)创建目录用户,并修改所属
ansible nfs -m group -a "name=www gid=666"
ansible nfs -m user -a "name=www uid=666 group=666 create_home=no shell=/sbin/nologin"
ansible nfs -m file -a "path=/data state=directory owner=666 group=666 recurse=yes"
)重载配置文件
ansible nfs -m shell -a "exportfs -arv" 或 ansible nfs -m service -a "name=nfs state=restarted"
ansible nfs -m shell -a "showmount -e"
)在web上挂载nfs的共享目录
ansible web -m yum -a "name=httpd state=installed"
ansible web -m service -a "name=httpd state=started"
ansible web -m mount -a "src=172.16.1.41:/data path=/var/www/html state=mounted fstype=nfs"
ansible nfs -m copy -a "content='xiao ming is your father' dest=/data/index.html"

10.script

).写个脚本,创建用户,并配置密码
[root@m01 scripts]# cat .sh
#!/bin/bash
useradd oldgirl
echo | passwd --stdin oldgirl &> /dev/null && echo 'create passwd success'
).运行脚本
ansible all -m script -a "/server/scripts/1.sh"

11.cron

- name
描述,必须要写,如果不写,默认为None,会导致无法指定删除某条计划任务
- job
任务,命令
- state
执行状态,absent 删除
present 创建(默认)
- minute
Minute when the job should run ( -, *, */, etc )
[Default: *]
- hour
Hour when the job should run ( -, *, */, etc )
[Default: *]
- day
Day of the month the job should run ( -, *, */, etc )
(Aliases: dom)[Default: *]
- weekday
Day of the week that the job should run ( - for Sunday-Saturday, *, etc
)(Aliases: dow)[Default: *]
- month
Month of the year the job should run ( -, *, */, etc )
[Default: *]
例子:每天的凌晨1点执行rsync_backup.sh
[root@m01 ~]# ansible all -m cron -a "name='Rsync backup' hour=1 minute=0 job='/bin/sh /server/scripts/rsync_backup.sh &> /dev/null'"

ansible批量部署模块(二)的更多相关文章

  1. Ansible批量部署工具

    Ansible:自动化运维工具 你需要在一台机器上yum install 一个包,这时候有一个需求,比如现在有5台机同时需要装apache这个包,那么100台呢,ssh上去就太慢了,这时候就借助到了a ...

  2. ansible 批量部署准备工作

    Ansible:自动化运维工具,基于Python开发 功能{ 批量系统配置 批量程序部署 批量运行命令等等 } 准备工作: 一.操作主机安装epel源 和 ansible工具 yum -y insta ...

  3. 利用ansible批量部署zabbix-agent

    应用环境:Linux运维工作少不了一个好的监控,zabbix就是目前比较好的一款开源监控软件. 监控类型多种多样,如果不介意或者系统支持安装,那么agent方式是首选. 当主机数量较多时,可以利用相关 ...

  4. ansible批量部署(一)

    自动化运维工具shell脚本/Ansible(无客户端)/Saltstack(master-minion) 回顾服务器部署的流程:买云主机->环境部署->软件部署->配置部署-> ...

  5. ansible批量部署mysql

    1.1 将mysql软件包同步到客户端服务器,做安装前期准备 Ps:mysql安装包线拖到ansible服务端的/ansible/roles/mysql/files目录下 vim /ansible/r ...

  6. ansible批量部署tomcat

    1.1 构建目录结构 此操作是安装nginx+mysql+tomcat+db的目录结构,可以参考一下,不错~ mkdir -p /ansible/roles/{nginx,mysql,tomcat,d ...

  7. Ansible批量部署工具的安装

    1.系统安装gcc,以及python2.6以上(2.6.8): 第一种比较简单的安装方法: 1)直接yum install -y ansible; 2)然后更改配置,/etc/ansible/ansi ...

  8. ansible批量部署nginx

    1.1 将nginx的安装包,和安装脚本copy到客户端,并安装脚本 vim /ansible/roles/nginx/tasks/main.yml - name: copy nginx_tar_gz ...

  9. Ansible安装部署以及常用模块详解

    一.  Ansible 介绍Ansible是一个配置管理系统configuration management system, python 语言是运维人员必须会的语言, ansible 是一个基于py ...

随机推荐

  1. 使用openssl做CA服务器,并且生成证书。

    [root@22 conf.d]# openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096  #ca私钥 [root@22 conf.d]# op ...

  2. linux服务重启命令

    /etc/init.d/sshd restart/etc/init.d/sshd reload systemctl status sshd.servicesystemctl restart sshd. ...

  3. quartz详解4:quartz线程管理

    http://blog.itpub.NET/11627468/viewspace-1766967/ quartz启动后有多个线程同时在跑.启动时会启动主线程.集群线程.检漏线程.工作线程.主线程负责查 ...

  4. P1426 小鱼会有危险吗

    题解: 在测试数据里有一个是临界值问题,探测范围是闭区间 #include<stdio.h>int main(){ double s,x;                   //注意:此 ...

  5. Integer和int的区别

    1.Integer是int的包装类,int则是java的一种基本数据类型 2.Integer变量必须实例化后才能使用,而int变量不需要 3.Integer实际是对象的引用,当new一个Integer ...

  6. 线程与进程 concurrent.futures模块

    https://docs.python.org/3/library/concurrent.futures.html 17.4.1 Executor Objects class concurrent.f ...

  7. 基于百度语音识别API的Python语音识别小程序

    一.功能概述 实现语音为文字,可以扩展到多种场景进行工作,这里只实现其基本的语言接收及转换功能. 在语言录入时,根据语言内容的多少与停顿时间,自动截取音频进行转换. 工作示例: 二.软件环境 操作系统 ...

  8. 201612-2 工资计算 Java

    思路: 税+税后所得A=税前工资S. 因为工资是整百的数,每次减100来判断.好理解但是超时. import java.util.Scanner; //只有90分,超时了 public class M ...

  9. 吴裕雄--天生自然 JAVASCRIPT开发学习:函数定义

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. Cpp:"->"和"."的区别

    environments:gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) class data{ publi ...