New version of salt-formula from Saltstack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.2KB

  1. {% from "salt/map.jinja" import control with context %}
  2. {%- if control.enabled and control.virt_enabled is defined %}
  3. include:
  4. - salt.minion
  5. salt_control_virt_packages:
  6. pkg.installed:
  7. - names: {{ control.virt_pkgs }}
  8. update-guestfs-appliance:
  9. cmd.wait:
  10. - watch:
  11. - pkg: salt_control_virt_packages
  12. {#
  13. {%- for package in control.virt_pips %}
  14. {{ package }}:
  15. pip.installed:
  16. - require:
  17. - pkg: salt_control_virt_packages
  18. {%- endfor %}
  19. #}
  20. /etc/salt/minion.d/_virt.conf:
  21. file.managed:
  22. - source: salt://salt/files/_virt.conf
  23. - user: root
  24. - group: root
  25. - template: jinja
  26. - require:
  27. - pkg: salt_control_virt_packages
  28. {%- if not grains.get('noservices', False) %}
  29. - watch_in:
  30. - service: salt_minion_service
  31. {%- endif %}
  32. {%- for cluster_name, cluster in control.cluster.iteritems() %}
  33. {%- if cluster.engine == "virt" %}
  34. {%- for node_name, node in cluster.node.iteritems() %}
  35. {%- if node.name is defined %}
  36. {%- set node_name = node.name %}
  37. {%- endif %}
  38. {%- if node.provider == grains.id %}
  39. {%- set size = control.size.get(node.size) %}
  40. salt_control_virt_{{ cluster_name }}_{{ node_name }}:
  41. module.run:
  42. - name: virtng.init
  43. - m_name: {{ node_name }}.{{ cluster.domain }}
  44. - cpu: {{ size.cpu }}
  45. - mem: {{ size.ram }}
  46. - image: {{ node.image }}
  47. - start: True
  48. - disk: {{ size.disk_profile }}
  49. - nic: {{ size.net_profile }}
  50. - kwargs:
  51. seed: True
  52. serial_type: pty
  53. console: True
  54. - unless: virsh list --all --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$"
  55. #salt_control_seed_{{ cluster_name }}_{{ node_name }}:
  56. # module.run:
  57. # - name: seed.apply
  58. # - path: /srv/salt-images/{{ node_name }}.{{ cluster.domain }}/system.qcow2
  59. # - id_: {{ node_name }}.{{ cluster.domain }}
  60. # - unless: virsh list | grep {{ node_name }}.{{ cluster.domain }}
  61. {%- if node.get("autostart", True) %}
  62. salt_virt_autostart_{{ cluster_name }}_{{ node_name }}:
  63. module.run:
  64. - name: virt.set_autostart
  65. - vm_: {{ node_name }}.{{ cluster.domain }}
  66. - state: true
  67. - unless: virsh list --autostart --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$"
  68. {%- endif %}
  69. {%- endif %}
  70. {%- endfor %}
  71. {%- endif %}
  72. {%- endfor %}
  73. {%- endif %}