Dynamic Inventory: no more host lists!

25,099 views

Published on

#ansibleja

Published in: Technology
3 Comments
24 Likes
Statistics
Notes
  • @James Cuzella We're not using Rakefile, and using custom .rb (kicked by custom `bin/kick-spec`) file to run spec file directly.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @James Cuzella I'm sorry for late reply.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I'm interested in the `kick-spec` tool mentioned in this presentation, and hearing more about how you are organizing your spec tests based on role. I'm mainly curious about how the `hosts:` line in a playbook is tied into a host group from Ansible inventory, and how the Rakefile is able to get information from inventory and connect that with the appropriate `spec/ROLE/` directory.

    There is a tool named `kick-spec` mentioned, but I don't see any source code or link provided to see what it's doing. Are you still using a `Rakefile` to start tests?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
25,099
On SlideShare
0
From Embeds
0
Number of Embeds
14,407
Actions
Shares
0
Downloads
64
Comments
3
Likes
24
Embeds 0
No embeds

No notes for slide

Dynamic Inventory: no more host lists!

  1. 1. Dynamic inventory: No more host list! #ansibleja Ansible勉強会#1 2014/06/10 @tagomoris 14年6月10日火曜日
  2. 2. TAGOMORI Satoshi (@tagomoris) LINE Corp. 14年6月10日火曜日
  3. 3. Ansible Batch server operations add routing table entry deploy ssh keys update openssl Install/update middleware Hadoop, Presto, Fluentd (and its config/code ...) 14年6月10日火曜日
  4. 4. Ansible: good points Minimal managed node requirements Simple tool chain and files YAML and many built-in modules Less stress of shell scripts Dynamic inventory 14年6月10日火曜日
  5. 5. Ansible: bad points Less japanese case-studies Less japanese books and blog entries Less japanese users? -> No! 14年6月10日火曜日
  6. 6. Inventory Hosts and groups Host variables / Group variables Group of groups ‘group_vars/’ and ‘host_vars/’ 14年6月10日火曜日
  7. 7. Inventory: example mail01.local globalip=192.168.0.11 [blog] www[01:30].blog.local virtualip=203.0.113.63 app[01:50].blog.local master01.db.blog.local server_id=.... slave0[1:4].blog.local server_id=..???? [linenantoka] www[01:10].nantoka.line.local 14年6月10日火曜日
  8. 8. ROLEs and TYPEs Roles (web, app, db, hadoop, ...) Groups (service-names, ...) OSs, Server models, Disk types (HDD, SSD, ioDrive, ...) IP addrs (local, global, virtual) ... and many more 14年6月10日火曜日
  9. 9. Yabitz Our host management tool/server: WebUI and WebAPI (json) hostname[s], status, service, CPU, memory, disk, rack position, size, local/global/virtual IPs, virtual/ parent server, .... tags changes(history, diff) anything links to other internal web tools 14年6月10日火曜日
  10. 10. Dynamic inventory Dynamic inventory plugins Cobbler external inventory script Example for linux install server AWS EC2 external inventory script Digital Ocean, Google Compute Engine, Linode, Zabbix, ... Mix inventories (static and dynamic) 14年6月10日火曜日
  11. 11. Custom dynamic inventory Original scripts AS dynamic inventory “Developing Dynamic Inventory Sources” http://docs.ansible.com/developing_inventory.html executable program implement `--list` implement `--host HOSTNAME` 14年6月10日火曜日
  12. 12. JSON: for `--list` Dynamic inventory: output { "databases": { "hosts": [ "host1.local", "host2.local" ], "vars": { "a": true } }, "webservers": [ "host2.local", "host3.local" ], "tokyo": { "hosts": [ "host1.local", "host4.local", "host5.local" ], "vars": { "b": false }, "children": [ "shibuya", "ebisu" ] }, "shibuya": [ "host6.local" ], "ebisu": [ "host7.local" ] } 14年6月10日火曜日
  13. 13. JSON: for `--host HOSTNAME` Dynamic inventory: output { “localip”: “192.0.2.53”, “virtualip”: “203.0.113.53”, “global_fqdn”: “tagomoris.example.com”, } 14年6月10日火曜日
  14. 14. Dynamic inventory reference 1. inventory --list 2. inventory --host host1.local 3. inventory --host host2.local 4. inventory --host host4.local 5. ... 14年6月10日火曜日
  15. 15. Playbook execution $ ansible-playbook PLAYBOOK_PATH.yml 14年6月10日火曜日
  16. 16. Yabitz inventory ansible-playbook bin/yabitz_inventory Yabitz playbooks/PLAYBOOK.yaml Servers 14年6月10日火曜日
  17. 17. Role based playbooks Flat playbook directory playbooks/*.yaml playbooks/SERVICE_NAME/*.yaml “hosts” are always roles hosts: centos hosts: centos6 hosts: hadoop-slave hosts: hadoop-all-nodes:fluentd-all-nodes 14年6月10日火曜日
  18. 18. Yabitz tags and ROLEs Tags Server-type-tag (by studio3104 crawler) centos centos5, centos6 Role-based-tag hadoop-all-nodes hadoop-master, service-hadoop-master2 hadoop-slave 14年6月10日火曜日
  19. 19. Implementation examples ansible.cfg [defaults] hostfile=/path/to/bin/yabitz_inventory commands $ ansible-playbook playbooks/update-openssl.yaml $ TARGET_HOSTS=host1.local,host2.local ansible-playbook playbooks/SERVICE/foo.yaml 14年6月10日火曜日
  20. 20. No more host lists! Ansible inventory is very simple and understandable But we cannot use it for real world operations especially for hundreds or thousands of hosts... Use dynamic inventory! 14年6月10日火曜日
  21. 21. Role based playbook testing Serverspec testing without breaking operations providing double check (beside of ansible) 14年6月10日火曜日
  22. 22. Serverspec directories from http://serverspec.org/tutorial.html host based spec directory tree spec/ SERVERNAME/ function_spec.rb and exec (`rake spec`) “How to share serverspec tests among hosts” http://serverspec.org/advanced_tips.html static file based test sharing 14年6月10日火曜日
  23. 23. Specs and roles Role based provisioning roles-to-hosts resolution MUST be done dynamically Helper command to get roles from playbooks and role based spec directory bin/kick-spec spec/ROLE/*_spec.rb 14年6月10日火曜日
  24. 24. Implementation example(2) $ bin/kick-spec playbooks/BOOK.yaml $ bin/kick-spec playbooks/BOOK.yaml --host host1.local --host host2.local $ bin/kick-spec --role latest_openssl --host host5.local 14年6月10日火曜日
  25. 25. Conclusion DO NOT write same data in 2 or more files USE master data from anywhere Dynamic inventory makes it possible! 14年6月10日火曜日
  26. 26. NO MORE HOST LISTS!!!!!!!! Thanks! 14年6月10日火曜日
  27. 27. Appendix: “_meta”(1) Special attribute of JSON for `--list` To include host variables in single JSON result No more exec: `--host HOST` { “shibuya”: [ “host6.local” ], “ebisu”: [ “host7.local” ], “_meta”: { “hostvars”: { “host6.local”: { “var1”: “value1”, “var2”: “value2” }, “host7.local”: { .... } } } } 14年6月10日火曜日
  28. 28. Without `_meta`: `--list` x1 and `--host` x1000 ! With `_meta`: `--list` x1 only! Appendix: “_meta”(2) 14年6月10日火曜日
  29. 29. Benchmark: time before task starts w/ yabitz_inventory for thousands of hosts Appendix: “_meta”(3) w/o _meta w/ _meta Elapsed time 18min! 10sec!!!! 14年6月10日火曜日

×