- 12 Nov 2024
-
DarkLight
-
PDF
create service ansible playbook
- Updated on 12 Nov 2024
-
DarkLight
-
PDF
iagctl create service ansible-playbook
Create a new ansible playbook service
Synopsis
This command will create an Ansible playbook service in the gateway data store. The service can later be executed via gateway run
command. Before creating an Ansible playbook service, you will need to ensure that a repository with the actual playbooks exists. See iagctl 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
You can specify that you want to use example-repo
via the --repository
flag.
Notice that the Ansible playbooks exist in a directory called upgrade-plays
. You can denote this using the --working-dir
flag.
Inside the upgrade-plays
directory, you have two different playbooks that will need to be executed when the service runs: upgrade-router.yml
and upgrade-switch.yml
. You 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 your 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 your working-dir
.
Several other Ansible specific flags such as forks
, limit
, skip-tags
, and verbosity
can also be specified.
The playbooks have several dependencies that are outlined within the requirements.yml
and requirements.txt
files.
- All dependencies are installed when the playbook service is executed using the gateway
run
command. - Within
requirements.txt
, you can specify the Ansible version. If no Ansible version is specified, the latest version will be installed. - The
requirements
files must be within theworking-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 iagctl create decorator -h
.
iagctl 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.
>_ iagctl create service ansible-playbook my-ansible-service \
--repository my-repo \
--playbook main.yml
Create a Complex Ansible Service
Creates an Ansible service that takes advantage of every available option.
>_ iagctl 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 used for a particular Ansible service. Multiple inventory files can be provided. The inventory files are loaded in order as 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 gateway 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 tags 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
CLI References
See related create
commands:
- create
- create decorator
- create repository
- create secret
- create service
- create service opentofu plan
- create service python script
- create user
For all CLI commands see → Command References Index