Creating a "Hello, torero" Service

Every good software project has a "hello world" example. So torero is no different. We will walk through a typical workflow of creating services and explain all the steps along the way. We will get you started executing simple Python, Ansible, and OpenTofu services. This example is not for production but to get a feel on how to use the application.

Import Resources

All the code that we write and that we want to be executed with torero must be placed somewhere. Git allows operators to easily share, revision and collaboratively work on different services.

torero requires a git repository to obtain the script to be used in a service. In this example we will use the following repository:

https://github.com/torerodev/hello-torero

It is important that you use a real git repository for this to work.

The quickest way to get started is to use the torero db import command that allows us to import resources that are listed in a file. In this example we will import the services listed in the following import.yml file.

To import the services in torero, we will use the torero db import command and reference the repository.

>_ torero db import --repository https://github.com/torerodev/hello-torero.git import.yml

torero should return results that show that a repository and three services have been created.

Output:

Successfully added 'repository/v1/hello-torero'
Successfully added 'services/v1/ansible-playbook/hello-ansible'
Successfully added 'services/v1/python-script/hello-python'
Successfully added 'services/v1/opentofu-plan/hello-opentofu'

Successfully added 4, replaced 0 and skipped 0 from the service file 'import.yml'

(Optional) Verify That The Repository And Services have been created

Repository

>_ torero get repositories
Output:

NAME           DESCRIPTION               URL                                             REFERENCE   TAGS           PRIVATE KEY NAME
hello-torero   Get started with torero   https://github.com/torerodev/hello-torero.git   main        demo, torero

For more information on repositories, see the repository command line documents

Services

>_ torero get services
Output:

NAME             DESCRIPTION            TYPE               TAGS             REGISTRIES
hello-ansible    Ansible hello world    ansible-playbook   demo, ansible
hello-opentofu   OpenTOFU hello world   opentofu-plan      demo, opentofu
hello-python     Python hello world     python-script      demo, python

For more information on the different service types, please refer to their documentation. - Ansible - Python - OpenTofu

Run a Service

Now that torero has some services and a repository within its data store, we can now execute the python service.

>_ torero run service python-script hello-python
Output:

Start Time:   2025-01-01T12:00:00Z
End Time:     2025-01-01T12:00:01Z
Elapsed Time: 1.543650s
Return Code:  0
Stdout:
Hello World!

Stderr:

It's that easy! You can also run the Ansible Playbook by running

>_ torero run service ansible-playbook hello-ansible

And the OpenTofu plan by running

>_ torero run service opentofu-plan apply hello-opentofu

Happy automating!