美文网首页
ansible模块

ansible模块

作者: carey_ff72 | 来源:发表于2017-06-02 15:58 被阅读0次

    文章来自于:ansible模块

    查看模块帮助

    ansible-doc -s module


    copy模块

    把本地文件copy到指定主机

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

    option:

    • backup: 在覆盖前,将源文件备份(yes|no)
    • dest: 目标路径
    • directory_mode: 设置目录权限
    • force: 如果目标主机包含该文件,是否强制覆盖(yes|no)
    • group: 指定属组
    • mode: 权限
    • owner: 属主
    • src: 源文件

    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:

    • group: 属组
    • mode: 权限
    • owner: 属主
    • path: 路径
    • recurse: 递归设置文件属性,只实用state=link
    • src: 源文件
    • dest: 目标文件,只实用state=link
    • state: 状态
      • directory: 如果目录不存在,就创建
      • file: 文件不存在,也不创建
      • link: 创建软链接
      • hard: 创建硬链接
      • touch: 如果文件不存在,则新建
      • absent: 删除目录,文件或取消链接文件

    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:

    • name:包名
    • state:
      • present: 安装(installed)
      • latest: 安装最新版
      • absent: 卸载

    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模块

    相关文章

      网友评论

          本文标题:ansible模块

          本文链接:https://www.haomeiwen.com/subject/jasufxtx.html