ansible-doc和playbook

ansible的adhoc

adhoc命令格式

ansible "host-pattern" -m “moudle” -a "mould argument" -I "inventory-path"

host-pattern 表示某个主机或主机组

-m 后面跟的是使用ansible模块

-a参数后面跟的是模块的参数

-i 参数后面跟的是inventory的路径

示例

[student@workstation deploy-manage]$ ansible internetweb -m ping

serverb.lab.example.com | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/libexec/platform-python"

    },

    "changed": false,

    "ping": "pong"

}

这个表示internetweb这个主机组内的主机去ping控制节点

2.常见模块

[student@workstation ~]$ ansible-doc -l  列出当前系统所有模块

[student@workstation deploy-manage]$ ansible -m user -a 'name=shihp uid=5000 state=present' web

使用user模块 添加shihp用户 uid设置为5000 state=present表示添加 web表示主机组(state=absent表示删除用户)

ansible特殊模块command

command模块就是能通过ansible在被管理主机上敲命令

如果ansible后面不加模块,也就是不加-m参数,就相当于在执行command模块

-u参数表示指定用户

[student@workstation deploy-manage]$ ansible web -m command -a "id" -u root

playbook

1,playbook和adhoc对比

adhoc只能运行一个tack

Play可以运行多个tack

platbook可以运行多个play

2,运行playbook

[student@workstation ~]$ cat test1.yml

---

- name: test #playbook描述

  hosts: servera #主机

  tasks: #格式

    - name: create a new user #tesks模块描述

      user: #模块名称

         name: shh

         uid: 1314

         state: present

[student@workstation ~]$ ansible-playbook test1.yml   #执行这个playbook

在写模块的时候可以使用ansible-doc 模块名来获取模块的帮助

注意语法,写完后

检查playbook语法问题

ansible-playbook --syntax-check yml文本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值