create service ansible-playbook

Create a new ansible playbook service

Synopsis

Create

This command will create an Ansible playbook service in torero's data store. The service can later be executed via torero's run command. Before creating an Ansible playbook service, you will need to ensure that a repository with the actual playbook(s) exists. See torero create repository -h for more information.

Consider Ansible playbooks that exists in a repository called example-repo. The repository has the following directory layout:

├── README.md
├── upgrade-plays
│   ├── upgrade-router.yml
│   ├── upgrade-switch.yml
│   ├── inventory.yml
│   ├── some-vars.yml
│   ├── requirements.yml
│   └── requirements.txt

We can specify that we want to use example-repo via the --repository flag.

Notice that our Ansible playbooks exist in a directory called upgrade-plays. We can denote this using the --working-dir flag.

Inside the upgrade-plays directory, we have two different playbooks that will need to be executed when our service runs: upgrade-router.yml and upgrade-switch.yml. We can specify their file names using the --playbook flag.

An inventory file can be specified using the --inventory flag. The inventory file must exist within the repository and the path to the file must be relative to our working-dir.

Any Ansible extra-vars that are required by the playbook can be passed in using the --extra-vars flag. Variables can be explicitly defined using key=value syntax or via JSON. e.g. {"key": "value"}.

A file within the repository that contains extra variables can be specified using the --extra-vars-file flag. The file must exist within the repository and the path to the file must be relative to our working-dir.

Several other Ansible specific flags such as forks, limit, skip-tags, and verbosity can also be specified.

Our playbooks have several dependencies that our outlined within the requirements.yml and requirements.txt files. All dependencies are installed when the playbook service is executed using torero's run command. Within requirements.txt, we can specify our Ansible version. If no Ansible version is specified, the latest version will be installed. These requirements files must be within the working-dir.

Finally, a decorator can be specified to allow for input validation when the service is executed via the run command. For more information on decorators, run torero create decorator -h.

torero create service ansible-playbook <service-name> --repository <string> --playbook <string> [flags]

Examples

Create A Simple Ansible Service

Creates a simple Ansible service called my-ansible-service where an Ansible playbook named main.yml is at the root of the my-repo repository.

>_ torero create service ansible-playbook my-ansible-service \
--repository my-repo \
--playbook main.yml

Create A More Complex Ansible Service

Creates an Ansible service that takes advantage of every available option.

>_ torero create service ansible-playbook upgrade-os \
--repository example-repo \
--working-dir ansible_with_inventory \
--playbook upgrade-router.yml \
--playbook upgrade-switch.yml \
--inventory inventory.yml \
--extra-vars 'version=3.0' \
--extra-vars '{"rollback": false}' \
--extra-vars-file some-vars.yml \
--verbosity 6 \
--diff \
--check \
--forks 1 \
--decorator my-decorator \
--description "Simple Hello World" \
--tag hello

Options

      --check                         Configures the service to not make any changes, instead just reporting potential
                                      changes.
      --config-file string            The path to an Ansible config file to be used when running the service. The file
                                      will be relative to the root of the working directory.
      --decorator string              The name of the decorator to be associated with the service
      --description string            A brief description of the service used for identification
      --diff --check                  When set, the service shows the differences without making any changes,
                                      typically used with the --check flag.
      --extra-vars stringArray        Variables referenced by Ansible. Accepts json or k=v pairs.
      --extra-vars-file stringArray   Path to an Ansible extra-vars file within the repository. Relative to the
                                      working directory.
      --forks int                     Forks specify number of parallel processes to use.
  -h, --help                          help for ansible-playbook
      --inventory stringArray         Inventory files that will be used for a particular Ansible service. Multiple
                                      inventory files can be provided. The inventory files are loaded in order that
                                      they are placed during creation. The path must be relative to the root of the
                                      working directory.
      --limit stringArray             Limit the number of hosts that a playbook can be run against.
      --playbook stringArray          The name of the Ansible playbook file in the repository. This must exist in the
                                      working-dir, if specified. More than one playbook can be ran sequentially by
                                      providing multiple flags. (default [main.yaml])
      --repository string             The repository within torero that contains the Ansible playbook or playbooks
                                      that are defined in the playbook flag.
      --skip-tags string              Tags for the Ansible service to skip. For multiple skip tags use a comma
                                      separator.
      --tag stringArray               Metadata tag(s) to associate with the service.
      --tags string                   Tags for the Ansible service to use. For multiple tags use a comma separator.
      --verbosity int                 Set the verbosity of output when running Ansible. The range is from 1 to 6. If
                                      you need -vvvv for example then this should be set as 4
      --working-dir string            The path to the directory where the playbook exists. The path must be relative
                                      to the root of the repository. If a working-dir is not provided the playbook
                                      will be executed from the repository's root.

Options inherited from parent commands

      --config string   Path to the configuration file
      --raw             Displays the result of the command in its raw format
      --verbose         Enable verbose output

SEE ALSO