ansible模块

2017-06-02  本文已影响0人  carey_ff72

文章来自于:ansible模块

查看模块帮助

ansible-doc -s module


copy模块

把本地文件copy到指定主机

ansible host_list -m copy -a 'src=/data/test.sh dest=/data/'

option:

fetch模块

从远程主机拉取文件

ansible host_list -m fetch -a 'src=/data/test.sh dest=/data/'

file模块

更改指定主机文件权限,属主,和数组

ansible host_list -m file -a 'dest=/data/test.sh mode=755 owner=root group=root'

option:

cron模块

在指定节点定义计划任务

ansible host_list -m cron -a 'name="test" minute=*/3 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate 172.16.1.1"'

group模块

在指定节点上创建用户组

ansible host_list -m group -a 'gid=2000 name=group1'

user模块

在指定节点上创建用户

ansiblie host_list -m user -a 'name=user state={present(创建)|absent(删除)} force=(是否强制删除家目录) groups=group1 shell=bash'

yum模块

yum安装软件

ansible host_list -m yum -a 'state=present name=httpd'

option:

service模块

启动节点上某服务,并开机自启动

ansible host_list -m service -a 'name=nginx state=restarted enabled=yes'

script模块

在指定节点上执行脚本

ansible host_list -m script -a '/data/script/test.sh'

ping模块

检查节点是否正常通信

ansible host_list -m ping

command模块

在指定节点上执行命令

ansible host_list -m command -a 'hostname'

get_url模块

在指定

ansible host_list -m get_url -a 'url=http://www.carzy.top/test.sh dest=/data'

synchronize模块

将某目录推送到指定节点某目录下

ansible host_list -m synchronize -a 'src=/data/src dest=/data compress=yes'

setup模块

返回指定主机相关信息

ansible host_list -m setup

user模块

用户管理
首先通过openssl命令来生成一个密码,因为ansible userpassword参数需要通过接受机密后的值。

$ echo ansible | openssl passwd -1 -stdin  
$1$PfV4LEdB$y.u791m56WQw9HpjGsDiD0

批量创建用户

$ ansible centos -m user -a 'name=carey password=$1$PfV4LEdB$y.u791m56WQw9HpjGsDiD0' -o
192.168.56.101 | SUCCESS => {"changed": true, "comment": "", "createhome": true, "group": 1000, "home": "/home/carey", "name": "carey", "password": "NOT_LOGGING_PASSWORD", "shell": "/bin/bash", "state": "present", "system": false, "uid": 1000}
192.168.56.102 | SUCCESS => {"changed": true, "comment": "", "createhome": true, "group": 1000, "home": "/home/carey", "name": "carey", "password": "NOT_LOGGING_PASSWORD", "shell": "/bin/bash", "state": "present", "system": false, "uid": 1000}

文章来自于carey的博客 :ansible模块

上一篇下一篇

猜你喜欢

热点阅读