Merge pull request #565 from ChristianLempa/556-enhance-and-update-kestra-flow-templates

fixed templates for 1.19 kestra
This commit is contained in:
Christian Lempa
2024-12-03 15:45:42 +01:00
committed by GitHub
11 changed files with 129 additions and 186 deletions
+35
View File
@@ -0,0 +1,35 @@
# Kestra ansible-playbook Template
# ---
#
# Run an ansible playbook cloned from a Git Repository
#
id: ansible_playbook_git
namespace: your_namespace # <-- Replace with your namespace...
tasks:
- id: ansible_job
type: io.kestra.plugin.core.flow.WorkingDirectory
inputFiles:
id_rsa: "{{ secret('RSA_SSH_KEY') }}" # <-- (Required) Replace with your secret key...
# id_ed25519: "{{ secret('ED25519_SSH_KEY') }}" # <-- (Optional) Replace with your secret key, when using ED25519...
tasks:
- id: git_clone
type: io.kestra.plugin.git.Clone
url: your-git-repository-url # <-- Replace with your Git repository URL...
directory: ansible
branch: main # <-- (Optional) Replace with your Git branch...
# --> (Optional) If Git repository is private, add your Git token...
# username: xcad
# password: "{{ secret('GITOKEN') }}"
# <--
- id: ansible_playbook
type: io.kestra.plugin.ansible.cli.AnsibleCLI
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
image: docker.io/cytopia/ansible:latest-tools
user: "1000" # <-- (Required) Replace with your user id...
env:
"ANSIBLE_HOST_KEY_CHECKING": "false"
"ANSIBLE_REMOTE_USER": "your-remote-user" # <-- (Required) Replace with your remote user...
commands:
- ansible-playbook -i ansible/inventory --key-file id_rsa ansible/your-playbook.yaml
# - ansible-playbook -i ansible/inventory --key-file id_ed25519 ansible/your-playbook.yaml # <-- (Optional) when using ED25519...
@@ -0,0 +1,37 @@
# Kestra ansible-playbook Template
# ---
#
# Run an ansible playbook defined inline the kestra flow.
#
id: ansible_playbook_inline
namespace: your_namespace # <-- Replace with your namespace...
tasks:
- id: ansible_job
type: io.kestra.plugin.core.flow.WorkingDirectory
inputFiles:
inventory.ini: | # <-- Replace with your inventory file content...
srv-demo-1.home.clcreative.de
myplaybook.yaml: | # <-- Replace with your playbook file content...
---
- hosts: srv-demo-1.home.clcreative.de
tasks:
- name: upgrade apt packages
become: true
ansible.builtin.apt:
upgrade: true
update_cache: true
id_rsa: "{{ secret('RSA_SSH_KEY') }}" # <-- (Required) Replace with your secret key...
# id_ed25519: "{{ secret('ED25519_SSH_KEY') }}" # <-- (Optional) Replace with your secret key, when using ED25519...
tasks:
- id: ansible_playbook
type: io.kestra.plugin.ansible.cli.AnsibleCLI
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
image: docker.io/cytopia/ansible:latest-tools
user: "1000" # <-- (Required) Replace with your user id...
env:
"ANSIBLE_HOST_KEY_CHECKING": "false"
"ANSIBLE_REMOTE_USER": "your-remote-user" # <-- (Required) Replace with your remote user...
commands:
- ansible-playbook -i inventory.ini --key-file id_rsa myplaybook.yaml
# - ansible-playbook -i inventory.ini --key-file id_ed25519 myplaybook.yaml # <-- (Optional) when using ED25519...
-42
View File
@@ -1,42 +0,0 @@
---
# Kestra ansible-playbook Template
# ---
#
# Run an ansible playbook defined inline the kestra flow.
#
id: ansible_job # <- Replace with your task id...
namespace: your-namespace # <- Replace with your namespace...
tasks:
- id: ansible # <- Replace with your task id...
type: io.kestra.plugin.core.flow.WorkingDirectory
tasks:
- id: local_files # <- Replace with your task id...
type: io.kestra.plugin.core.storage.LocalFiles
inputs:
inventory.ini: | # <- Replace with your inventory file content...
srv-demo-1.home.clcreative.de
myplaybook.yaml: | # <- Replace with your playbook file content...
---
- hosts: srv-demo-1.home.clcreative.de
tasks:
- name: upgrade apt packages
become: true
ansible.builtin.apt:
upgrade: true
update_cache: true
# <--
id_rsa: "{{ secret('SSH_KEY') }}" # <- Replace with your secret key...
- id: ansible_task # <- Replace with your task id...
type: io.kestra.plugin.ansible.cli.AnsibleCLI
docker:
image: docker.io/cytopia/ansible:latest-tools
user: "1000" # required to set ssh key permissions
env:
"ANSIBLE_HOST_KEY_CHECKING": "false"
# --> (optional) when using a different remote user
# "ANSIBLE_REMOTE_USER": "your-remote-user"
# <--
commands:
- ansible-playbook -i inventory.ini --key-file id_rsa myplaybook.yaml # <- Replace with your inventory and playbook files...
-33
View File
@@ -1,33 +0,0 @@
---
# Kestra ansible-playbook Template
# ---
#
# Run an ansible playbook which has been uploaded to the server.
#
id: ansible_job # <- Replace with your task id...
namespace: your-namespace # <- Replace with your namespace...
tasks:
- id: ansible # <- Replace with your task id...
type: io.kestra.plugin.core.flow.WorkingDirectory
tasks:
- id: ansible_task # <- Replace with your task id...
namespaceFiles:
enabled: true
# --> upload your files to the kestra data directory for the namespace in
# <docker volume for kestra-data>/<namespace>/_files/
include:
- inventory.ini # <- Replace with your inventory file...
- myplaybook.yaml # <- Replace with your playbook file...
# <--
type: io.kestra.plugin.ansible.cli.AnsibleCLI
docker:
image: docker.io/cytopia/ansible:latest-tools
env:
"ANSIBLE_HOST_KEY_CHECKING": "false"
# --> (optional) when using a different remote user
# "ANSIBLE_REMOTE_USER": "your-remote-user"
# <--
commands:
- apk add sshpass # <- (Optional) Only required if use ssh passwords.
- ansible-playbook -i inventory.ini myplaybook.yaml # <- Replace with your inventory and playbook files...
-38
View File
@@ -1,38 +0,0 @@
---
# Kestra ansible-playbook Template
# ---
#
# Run an ansible playbook which has been uploaded to the server, using
# ssh key authentication.
#
id: ansible_job # <- Replace with your task id...
namespace: your-namespace # <- Replace with your namespace...
tasks:
- id: ansible # <- Replace with your task id...
type: io.kestra.plugin.core.flow.WorkingDirectory
tasks:
- id: load_ssh_key # <- Replace with your task id...
type: io.kestra.plugin.core.storage.LocalFiles
inputs:
id_rsa: "{{ secret('SSH_KEY') }}" # <- Replace with your secret key...
- id: ansible_task
namespaceFiles:
enabled: true
# --> upload your files to the kestra data directory for the namespace in
# <docker volume for kestra-data>/<namespace>/_files/
include:
- inventory.ini # <- Replace with your inventory file...
- myplaybook.yaml # <- Replace with your playbook file...
# <--
type: io.kestra.plugin.ansible.cli.AnsibleCLI
docker:
image: docker.io/cytopia/ansible:latest-tools
user: "1000" # required to set ssh key permissions
env:
"ANSIBLE_HOST_KEY_CHECKING": "false"
# --> (optional) when using a different remote user
# "ANSIBLE_REMOTE_USER": "your-remote-user"
# <--
commands:
- ansible-playbook -i inventory.ini --key-file id_rsa myplaybook.yaml # <- Replace with your inventory and playbook files...
@@ -1,27 +1,26 @@
---
# Kestra Docker Git Build Template
# ---
#
# Build a Docker image from a Git repository.
#
id: docker-git-build # <- Replace with your task id...
namespace: your-namespace # <- Replace with your namespace...
id: docker_build_git
namespace: your_namespace # <- Replace with your namespace...
tasks:
- id: git # <- Replace with your task id...
- id: docker_job
type: io.kestra.plugin.core.flow.WorkingDirectory
tasks:
- id: clone # <- Replace with your task id...
- id: git_clone
type: io.kestra.plugin.git.Clone
url: https://your-git-repo-url # <- Replace with your Git repository URL...
branch: your-branch # <- Replace with your Git branch...
- id: build # <- Replace with your task id...
url: your-git-repository-url # <-- Replace with your Git repository URL...
directory: docker
branch: main # <-- (Optional) Replace with your Git branch...
# --> (Optional) If Git repository is private, add your Git token...
# username: xcad
# password: "{{ secret('GITOKEN') }}"
# <--
- id: docker_build
type: io.kestra.plugin.docker.Build
dockerfile: "src/Dockerfile" # <- Replace with your Dockerfile path...
dockerfile: "docker/src/Dockerfile" # <- Replace with your Dockerfile path...
tags:
- your-username/your-repository:your-tag # <- Replace with your Docker image tag...
push: true
+32
View File
@@ -0,0 +1,32 @@
# Kestra Docker File Build Template
# ---
#
# Build a Docker image from a File.
#
id: docker_build_inline
namespace: your_namespace # <- Replace with your namespace...
tasks:
- id: docker_job
type: io.kestra.plugin.core.flow.WorkingDirectory
inputFiles:
Dockerfile: | # <- Replace with your Dockerfile content...
FROM alpine:latest
WORKDIR /app
COPY . /app
RUN apk add --update python3
CMD [ "python", "main.py"]
main.py: | # <- Replace with your Python script content...
if __name__ == "__main__":
print("Hello from Docker!")
exit(0)
tasks:
- id: docker_build
type: io.kestra.plugin.docker.Build
dockerfile: "src/Dockerfile" # <- Replace with your Dockerfile path...
tags:
- your-username/your-repository:your-tag # <- Replace with your Docker image tag...
push: true
credentials:
registry: https://index.docker.io/v1/
username: "{{ secret('YOUR_USERNAME') }}" # <- Replace with your Docker Hub username...
password: "{{ secret('YOUR_PASSWORD') }}" # <- Replace with your Docker Hub password...
-39
View File
@@ -1,39 +0,0 @@
---
# Kestra Docker File Build Template
# ---
#
# Build a Docker image from a File.
#
id: docker-file-build # <- Replace with your task id...
namespace: your-namespace # <- Replace with your namespace...
tasks:
- id: file # <- Replace with your task id...
type: io.kestra.plugin.core.flow.WorkingDirectory
tasks:
- id: createFiles # <- Replace with your task id...
type: io.kestra.plugin.core.storage.LocalFiles
inputs:
Dockerfile: | # <- Replace with your Dockerfile content...
FROM alpine:latest
WORKDIR /app
COPY . /app
RUN apk add --update python3
CMD [ "python", "main.py"]
main.py: | # <- Replace with your Python script content...
if __name__ == "__main__":
print("Hello from Docker!")
exit(0)
- id: build # <- Replace with your task id...
type: io.kestra.plugin.docker.Build
dockerfile: "src/Dockerfile" # <- Replace with your Dockerfile path...
tags:
- your-username/your-repository:your-tag # <- Replace with your Docker image tag...
push: true
credentials:
registry: https://index.docker.io/v1/
username: "{{ secret('YOUR_USERNAME') }}" # <- Replace with your Docker Hub username...
password: "{{ secret('YOUR_PASSWORD') }}" # <- Replace with your Docker Hub password...
View File
@@ -1,4 +1,3 @@
---
# Kestra Python Command Template
# ---
#
@@ -8,14 +7,13 @@
# make sure the Kestra instance can access the /app/scripts/your-python-script.py file
# if you're running Kestra in Docker, use a volume to mount the file/directory.
#
id: python-command # <- Replace with your task id...
namespace: your-namespace # <- Replace with your namespace...
id: python_command
namespace: your_namespace # <-- Replace with your namespace...
tasks:
- id: python_command
- id: python_job
type: io.kestra.plugin.scripts.python.Commands
commands:
- python /app/scripts/your-python-script.py
runner: PROCESS # or DOCKER (might be deprecated in the future) use TaskRunner instead
taskRunner:
type: io.kestra.plugin.core.runner.Process
@@ -1,18 +1,15 @@
---
# Kestra Python Command Template
# ---
#
# This template is a simple Python script that can be used to make a request to a website and log the status code.
#
id: python-script # <- Replace with your task id...
namespace: your-namespace # <- Replace with your namespace...
id: python_script
namespace: your_namespace # <-- Replace with your namespace...
tasks:
- id: python_script
- id: python_job
type: io.kestra.plugin.scripts.python.Script
runner: DOCKER # (might be deprecated in the future) use TaskRunner instead
taskRunner:
type: io.kestra.plugin.core.runner.Process
script: |
from kestra import Kestra
import requests
@@ -21,9 +18,6 @@ tasks:
print(response.status_code)
Kestra.outputs({'status': response.status_code, 'text': response.text})
beforeCommands:
- pip install requests kestra
- id: log
type: io.kestra.core.tasks.log.Log
type: io.kestra.plugin.core.log.Log
message: "StatusCode: {{outputs.pythonscript.vars.status}}"