Bo's Oracle Station

查看: 1695|回复: 0

ansible1

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2020-12-9 20:11:53 | 显示全部楼层 |阅读模式
inventory:

  1. [othergroup]
  2. servera

  3. [dbgroup]
  4. serverb

  5. [prod]
  6. serverc
  7. serverd

  8. [balancers]
  9. serverb

  10. [webgroup:children]
  11. prod

  12. [srvgroup]
  13. serverb
  14. serverc
  15. serverd

复制代码
v1-1_all.sh:
  1. #!/bin/sh
  2. echo "webgroup:"
  3. ansible webgroup --list-hosts
  4. echo
  5. sleep 3

  6. echo "dbgroup:"
  7. ansible dbgroup --list-hosts
  8. echo
  9. sleep 3

  10. echo "othergroup:"
  11. ansible othergroup --list-hosts
  12. echo
  13. sleep 3

  14. echo "webgroup OR dbgroup:"
  15. ansible 'webgroup:dbgroup' --list-hosts
  16. echo
  17. sleep 3

  18. echo "srvgroup:"
  19. ansible srvgroup --list-hosts
  20. echo
  21. sleep 3

  22. echo "webgroup AND dbgroup:"
  23. ansible 'webgroup:&dbgroup' --list-hosts
  24. echo
  25. sleep 3

  26. echo "webgroup NOT dbgroup:"
  27. ansible 'webgroup:!dbgroup' --list-hosts
  28. echo
  29. sleep 3

  30. echo "******************************************"
  31. echo "NOT > OR > AND"
  32. echo "******************************************"
  33. sleep 10

  34. echo "webgroup AND (dbgroup OR  othergroup)"
  35. echo "COMMAND: webgroup:&dbgroup:othergroup"
  36. ansible 'webgroup:&dbgroup:othergroup' --list-hosts
  37. echo
  38. sleep 3

  39. echo "(webgroup NOT dbgroup) OR othergroup"
  40. echo "COMMAND: webgroup:!dbgroup:othergroup"
  41. ansible 'webgroup:!dbgroup:othergroup' --list-hosts
  42. echo
  43. sleep 3

  44. echo "(webgroup NOT dbgroup) AND othergroup"
  45. echo "COMMAND: webgroup:!dbgroup:&othergroup"
  46. ansible 'webgroup:!dbgroup:&othergroup' --list-hosts
  47. echo
  48. sleep 3

  49. echo "webgroup OR (dbgroup NOT othergroup)"
  50. echo "COMMAND: webgroup:dbgroup:!othergroup"
  51. ansible 'webgroup:dbgroup:!othergroup' --list-hosts
  52. echo
复制代码
v-1-1-1_all.sh

  1. ansible 's*' --list-hosts
  2. ansible servera,serverb --list-hosts
  3. ansible-inventory --graph
复制代码


hosts (4):
    serverb
    serverc
    serverd
    servera
  hosts (2):
    servera
    serverb
@all:
  |--@balancers:
  |  |--serverb
  |--@dbgroup:
  |  |--serverb
  |--@othergroup:
  |  |--servera
  |--@srvgroup:
  |  |--serverb
  |  |--serverc
  |  |--serverd
  |--@ungrouped:
  |--@webgroup:
  |  |--@prod:
  |  |  |--serverc
  |  |  |--serverd
  |  |  |--serverc
  |  |  |--serverd

v1-2_svrvgroup.yml
  1. ---
  2. - name: Create User Spoto
  3.   hosts: srvgroup
  4.   tasks:
  5.   - name: Create Group sharedgroup
  6.     group:
  7.       name: sharedgroup
  8.       gid: 6000

  9.   - name: Create User secoug
  10.     user:
  11.       name: secoug
  12.       uid: 7000
  13.       group: sharedgroup
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-11-1 09:05 , Processed in 0.038887 second(s), 24 queries .

快速回复 返回顶部 返回列表