当前位置: 首页 > 文档资料 > Ansible 入门 >

Ansible进阶 - 写出更好的Playbook脚本

优质
小牛编辑
131浏览
2023-12-01
  • 鼓励文件的重用,尽量使用include和role避免重复的代码。

  • 尽量把大的文件分成小的文件

https://github.com/ansible/ansible-examples

  1. production # inventory file for production servers
  2. staging # inventory file for staging environment
  3. group_vars/
  4. group1 # here we assign variables to particular groups
  5. group2 # ""
  6. host_vars/
  7. hostname1 # if systems need specific variables, put them here
  8. hostname2 # ""
  9. library/ # if any custom modules, put them here (optional)
  10. filter_plugins/ # if any custom filter plugins, put them here (optional)
  11. site.yml # master playbook
  12. webservers.yml # playbook for webserver tier
  13. dbservers.yml # playbook for dbserver tier
  14. roles/
  15. common/ # this hierarchy represents a "role"
  16. tasks/ #
  17. main.yml # <-- tasks file can include smaller files if warranted
  18. handlers/ #
  19. main.yml # <-- handlers file
  20. templates/ # <-- files for use with the template resource
  21. ntp.conf.j2 # <------- templates end in .j2
  22. files/ #
  23. bar.txt # <-- files for use with the copy resource
  24. foo.sh # <-- script files for use with the script resource
  25. vars/ #
  26. main.yml # <-- variables associated with this role
  27. defaults/ #
  28. main.yml # <-- default lower priority variables for this role
  29. meta/ #
  30. main.yml # <-- role dependencies
  31. webtier/ # same kind of structure as "common" was above, done for the webtier role
  32. monitoring/ # ""
  33. fooapp/ # ""