[root@node1 ~]#ansible websrvs -m group -a "name=haproxy system=no state=present"---state为状态,指明是创建还是删除,创建用present,删除用absent
[root@node1 ~]#ansible websrvs -m group -a "name=haproxy system=no state=absent"---删除组
[root@node1 ~]#ansible websrvs -C -m group -a "name=haproy system=no state=present"---先干跑一边看有没有错误
5、user模块:管理用户账号
[root@node1 ~]#ansible websrvs -m user -a "name=tom groups=haproxy state=present uid=3000 shell=/usr/bin/sh"
[root@node1 ~]#ansible websrvs -m user -a "name=tom groups=haproxy state=present uid=3000 shell=/usr/bin/sh generate_ssh_key=true" ---创建用户并生成公钥私钥对
6、copy模块: 复制文件或者目录到远程
[root@node1 ~]#vim /app/test.txt
[root@node1 ~]#cat /app/test.txt
hellow magedu
welcome
[root@node1 ~]#ansible all -m copy -a "src=/app/test.txt dest=/app/ owner=daemon group=nobody mode=664"
[root@node1 ~]#ansible all -m copy -a "content='hellow true\n how are you\n' dest=/app/text2.txt" ---也可以复制一个内容到远程主机文件中
7、fetch模块:从远程主机取文件
[root@node1 ~]#ansible 192.168.243.10 -m fetch -a "src=/etc/fstab dest=/app/fstab" ---注意这里只能在一台主机上取
8、file模块:设置文件的属性、创建空文件和目录软连接等
[root@node1 ~]# ansible all -m file -a "path=/app/hidir state=directory owner=nobody mode=770"---在远程主机创建一个空目录,并指定权限
[root@node1 ~]# ansible all -m file -a "path=/app/ff state=touch owner=nobody mode=770"---创建空文件并指定权限,注意这里只能用touch
[root@node1 ~]# ansible all -m file -a "path=/app/ff state=file owner=daemon mode=770"---file只能用于已经存在文件修改权限,如果文件不存在不会创建
[root@node1 ~]# ansible all -m file -a "path=/app/fff src=/app/ff state=link"--- 创建一个软链接文件/app/fff指向源文件/app/ff
注意:state属性的可用值:file,directory,link,hard,touch,absent
[root@node1 ~]#ansible all -m file -a "path=/app/fff state=absent"---删除文件
9、get_url模块: Downloads files from HTTP, HTTPS, or FTP to node
[root@node1 app]#ansible all -m get_url -a "url=http://mirrors.sohu.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 dest=/app" ---下载网上的文件到多台主机
常用的参数: *url, *dest,sha256sum,owner, group, mode,*表示必须给定的
[root@node1 app]#ansible websrvs -m git -a "repo=https://github.com/happyfish100/fastdfs.git dest=/app/fastdfs" ---可以在github上下载软件或者文件到远程多台主机
16、haproxy模块:Enable, disable, and set weights for HAProxy backend servers using socket commands.
常用参数: backend、 host、 state、 weight
可以标记多台后端主机的状态,实现灰度发布