• ansible系列2-常用命令


    copy
    ansible oldboy -m copy -a "src=/etc/hosts dest=/tmp/ mode=0600 owner=oldboy group=oldboy "

    创建目录
    ansible oldboy -m file -a "dest=/tmp/oldboy_dir state=directory"

    创建文件
    ansible oldboy -m file -a "dest=/tmp/oldboy_file state=touch"

    创建软连接
    ansible oldboy -m file -a "src=/tmp/oldboy_file dest=/tmp/oldboy_file_link state=link"

    删除目录文件信息
    state=absent 目录将被递归删除以及文件,而链接将被取消链接
    ansible oldboy -m file -a "dest=/tmp/oldboy_dir state=absent"
    ansible oldboy -m file -a "dest=/tmp/oldboy_file state=absent"

    创建多级目录
    ansible oldboy -m copy -a "src=/etc/hosts dest=/tmp/01/0/0/0/0/0/0/0/"

    从远程拉取文件
    ansible oldboy -m fetch -a "dest=/tmp/backup src=/etc/hosts"
    flat 参数,拉去的时候不创建目录(同名文件会覆盖)
    ansible oldboy -m fetch -a "dest=/tmp/backup/ src=/etc/hosts flat=yes"

    mount参数实例
    挂载
    ansible 172.16.1.8 -m mount -a "fstype=nfs opts=rw path=/mnt/ src=172.16.1.31:/data/ state=mounted"
    卸载
    ansible 172.16.1.8 -m mount -a "fstype=nfs opts=rw path=/mnt/ src=172.16.1.31:/data/ state=unmounted"

    cron模块
    添加定时任务
    ansible oldboy -m cron -a "minute=0 hour=0 job='/bin/sh /server/scripts/hostname.sh &>/dev/null' name=oldboy01"
    删除定时任务
    ansible oldboy -m cron -a "minute=00 hour=00 job='/bin/sh /server/scripts/hostname.sh &>/dev/null' name=oldboy01
    只用名字就可以删除
    ansible oldboy -m cron -a "name=oldboy01 state=absent"
    注释定时任务
    ansible oldboy -m cron -a "name=oldboy01 job='/bin/sh /server/scripts/hostname.sh &>/dev/null' disabled=yes"
    取消注释
    ansible oldboy -m cron -a "name=oldboy01 job='/bin/sh /server/scripts/hostname.sh &>/dev/null' disabled=no"

    yum 模块
    ansible oldboy -m yum -a "name=nmap state=installed"

    service模块
    ansible oldboy -m service -a "name=crond state=restarted"

    hostname 修改主机名模块
    ansible 172.16.1.8 -m hostname -a "name=web01"

    selinux 管理模块
    ansible 172.16.1.8 -m selinux -a "state=disabled"

    get_url 模块 == 【wget】
    ansible 172.16.1.8 -m get_url -a "url=http://lan.znix.top/RDPWrap-v1.6.1.zip dest=/tmp/"

    sudo的使用

    ansible omg -S -R root -m shell -a ""   --sudo -k -K --user=XXXX

    ansible-playbook -C webservice.yml -s -U zhangjian -k -e "host=test user=zhangjian"

  • 相关阅读:
    c++ 指定目录下的文件遍历
    c++ 实现键盘钩子
    c++ 用模板类实现顺序储存的线性表
    c++ 递归算法实现排列组合
    matlab 基础知识
    QT 给工程添加图片
    QT5.9 QString和字符串转换的乱码问题
    【内核】——进程3,内核同步
    Java多线程——Thread的native底层实现
    【内核】——文件和文件系统的内部结构4 系统调用的实现
  • 原文地址:https://www.cnblogs.com/kuku0223/p/7766921.html
Copyright © 2020-2023  润新知