103 lines
3.2 KiB
Plaintext
103 lines
3.2 KiB
Plaintext
|
{% macro pod_deploy(pod) -%}
|
||
|
|
||
|
{%- if pillar['pods'][pod]['ip'] is defined %}
|
||
|
Configure static IP for {{ pod }}:
|
||
|
cmd.run:
|
||
|
- name: nmcli connection modify {{ pillar['pods'][pod]['ip']['dev'] }} +ipv4.addresses "{{ pillar['pods'][pod]['ip']['address'] }}/24"
|
||
|
- unless: ip -brief a | grep "{{ pillar['pods'][pod]['ip']['address'] }}/24"
|
||
|
|
||
|
Restart connection for {{ pod }} IP config:
|
||
|
cmd.run:
|
||
|
- name: nmcli connection down {{ pillar['pods'][pod]['ip']['dev'] }}; nmcli connection up {{ pillar['pods'][pod]['ip']['dev'] }}
|
||
|
- onchanges:
|
||
|
- cmd: Configure static IP for {{ pod }}
|
||
|
{%- endif %}
|
||
|
|
||
|
Create pod manage file for {{ pod }}:
|
||
|
file.managed:
|
||
|
- name: "/root/bin/{{ pod }}.sh"
|
||
|
- source: salt://pod/files/pod.sh.jinja
|
||
|
- template: jinja
|
||
|
- user: root
|
||
|
- group: root
|
||
|
- mode: "0750"
|
||
|
- context:
|
||
|
pod: {{ pod }}
|
||
|
args: {{ pillar['pods'][pod] }}
|
||
|
|
||
|
Create pod {{ pod }}:
|
||
|
cmd.run:
|
||
|
- name: "/root/bin/{{ pod }}.sh --create"
|
||
|
- unless: podman pod exists {{ pod }}
|
||
|
|
||
|
Create pod {{ pod }} unit file:
|
||
|
cmd.run:
|
||
|
- name: "/root/bin/{{ pod }}.sh --generate-systemd"
|
||
|
- onchanges:
|
||
|
- cmd: Create pod {{ pod }}
|
||
|
|
||
|
Run user daemon reload for {{ pod }} unit:
|
||
|
cmd.run:
|
||
|
- name: systemctl daemon-reload
|
||
|
- onchanges:
|
||
|
- cmd: Create pod {{ pod }} unit file
|
||
|
|
||
|
start pod {{ pod }}:
|
||
|
service.running:
|
||
|
- name: {{ pod }}.service
|
||
|
- enable: True
|
||
|
- onchanges:
|
||
|
- cmd: Run user daemon reload for {{ pod }} unit
|
||
|
{% endmacro -%}
|
||
|
{% macro container_deploy(container) -%}
|
||
|
|
||
|
{%- if pillar['containers'][container]['ip'] is defined %}
|
||
|
Configure static IP for {{ container }}:
|
||
|
cmd.run:
|
||
|
- name: nmcli connection modify {{ pillar['containers'][container]['ip']['dev'] }} +ipv4.addresses "{{ pillar['containers'][container]['ip']['address'] }}/24"
|
||
|
- unless: ip -brief a | grep "{{ pillar['containers'][container]['ip']['address'] }}/24"
|
||
|
|
||
|
Restart connection for {{ container }} IP config:
|
||
|
cmd.run:
|
||
|
- name: nmcli connection down {{ pillar['containers'][container]['ip']['dev'] }}; nmcli connection up {{ pillar['containers'][container]['ip']['dev'] }}
|
||
|
- onchanges:
|
||
|
- cmd: Configure static IP for {{ container }}
|
||
|
{%- endif %}
|
||
|
|
||
|
Create container manage file for {{ container }}:
|
||
|
file.managed:
|
||
|
- name: "/root/bin/{{ container }}.sh"
|
||
|
- source: salt://containers/files/container.sh.jinja
|
||
|
- template: jinja
|
||
|
- user: root
|
||
|
- group: root
|
||
|
- mode: "0750"
|
||
|
- context:
|
||
|
container: {{ container }}
|
||
|
args: {{ pillar['containers'][container] }}
|
||
|
|
||
|
Create container {{ container }}:
|
||
|
cmd.run:
|
||
|
- name: "/root/bin/{{ container }}.sh --create"
|
||
|
- unless: podman container exists {{ container }}
|
||
|
|
||
|
Create container {{ container }} unit file:
|
||
|
cmd.run:
|
||
|
- name: podman generate systemd --name {{ container }} > /etc/systemd/system/{{ container }}.service
|
||
|
- onchanges:
|
||
|
- cmd: Create container {{ container }}
|
||
|
|
||
|
Run user daemon reload for {{ container }} unit:
|
||
|
cmd.run:
|
||
|
- name: systemctl daemon-reload
|
||
|
- onchanges:
|
||
|
- cmd: Create container {{ container }} unit file
|
||
|
|
||
|
start container {{ container }}:
|
||
|
service.running:
|
||
|
- name: {{ container }}.service
|
||
|
- enable: True
|
||
|
- onchanges:
|
||
|
- cmd: Run user daemon reload for {{ container }} unit
|
||
|
{% endmacro -%}
|