ansible使用

配置文件在/etc/ansible/ansible.cfg

默认hosts文件位置在/etc/ansible/hosts
hosts
[web]
192.168.1.6
连通性测试
[root@192 ~]# ansible web -m ping(web是组名)
192.168.1.6 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
shell模块
[root@192 ~]# ansible web -m shell -a 'pwd | echo "hello"'
192.168.1.6 | CHANGED | rc=0 >>
hello

copy 模块
backup=yes 设置备份

[root@192 ~]# ansible web -m copy -a 'src=./sed_test.txt dest=/root/sed_test.txt'
192.168.1.6 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "checksum": "63bea2e3b0c7cd2d1f98bc5b7a9951eafcfead0f", 
    "dest": "/root/sed_test.txt", 
    "gid": 0, 
    "group": "root", 
    "mode": "0644", 
    "owner": "root", 
    "path": "/root/sed_test.txt", 
    "secontext": "system_u:object_r:admin_home_t:s0", 
    "size": 4, 
    "state": "file", 
    "uid": 0
}

fetch 模块
该模块用于从远程某主机获取(复制)文件到本地。

dest:用来存放文件的目录
src:在远程拉取的文件,并且必须是一个file,不能是目录
[root@192 ~]# ansible web -m fetch -a 'src=/root/ao.sh dest=/root/ao.sh'
192.168.1.6 | CHANGED => {
    "changed": true, 
    "checksum": "cb2071ef6f84065bd6ac068a48e6e4c0b9e102d5", 
    "dest": "/root/ao.sh/192.168.1.6/root/ao.sh", 
    "md5sum": "c6d35da4851099ff3376063890cc6141", 
    "remote_checksum": "cb2071ef6f84065bd6ac068a48e6e4c0b9e102d5", 
    "remote_md5sum": null
}

script 模块

chmod +x /root/b.sh
[root@192 ~]# ansible web -m script -a '/root/b.sh'
192.168.1.6 | CHANGED => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 192.168.1.6 closed.\r\n", 
    "stderr_lines": [
        "Shared connection to 192.168.1.6 closed."
    ], 
    "stdout": "", 
    "stdout_lines": []
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值