The module lifecycle stage: Experimental
The module has requirements for installation
Before enabling the module, you need to allow the use of experimental modules in the deckhouse ModuleConfig. To do this, set the allowExperimentalModules parameter to true.
This page collects ready-made scenarios for the ansible module in Deckhouse Platform (DP). The scenarios are independent, and each one includes a manifest and a description of what appears in the status of the run after it ends. The user guide describes every field of a run. Here, the runner Pod is a temporary Pod where DP executes the ansible-playbook utility.
Before you start
Every example expects the demo namespace, two virtual machines (VMs) demo-vm-01 and demo-vm-02 labeled role: demo, and the ssh-creds Secret with SSH credentials. Prepare those objects before you try the examples.
Connectivity check with an inline playbook
The simplest scenario executes a single-task playbook on the virtual machines (VMs) with a given label and goes through every step of a run, from the creation of the object to the result in its status. It is a good starting point for getting to know the module.
Playbook from a ConfigMap
A playbook longer than a few dozen lines, or one that several runs use, is better kept in a ConfigMap resource. The run then refers to a key of that ConfigMap and does not contain the playbook text.
Selecting several targets
A run selects virtual machines (VMs) with a label selector or with a list of names, and the example below shows both ways. The rules of target selection are described in the Virtual machines section of the user guide.
Debugging a run
The runner block helps you find out what a playbook does. It changes how the ansible-playbook utility executes the playbook, not which tasks it executes. The diff parameter shows what exactly changed in files, verbosity sets the level of detail in the log, and dryRun starts a check without changes on the hosts.
Groups and host variables in annotations
Annotations on a virtual machine (VM) set Ansible groups and host variables. DP copies these annotations into the inventory of every run, so the playbook receives the web group and the app_role variable without changes to the run manifest.
Installing a package with privilege escalation
Set the become: true parameter for tasks that change the system. DP takes the privilege escalation password from the become-password key of the connection Secret. The playbook in the example chooses the package manager from the facts Ansible gathered.
Idempotent configuration of a service
The playbook configures the service with a config file and a handler that reloads the service only if the file changes. A repeated run with the same playbook does not change the configuration and does not reload the service.
Collecting facts about VMs
For an inventory of virtual machines (VMs) and a capacity estimate, use a playbook that only gathers and prints facts and changes nothing. The result of such a playbook stays only in the logs of the runner Pod.
Encrypted values in Ansible Vault
A project with files encrypted by Ansible Vault is executed unchanged if the password is in the ansible-vault-password key of the connection Secret. DP passes that password to the ansible-playbook utility as a password file.
Playbook from a public Git repository
The Git source fetches the whole repository, so an Ansible project with roles/, group_vars/ directories and templates is executed unchanged. DP installs the declared Galaxy dependencies before the playbook starts.
Private Git repository
The credentials of a private repository are kept in a separate Secret. DP passes them only to the fetch step, so the tasks of the playbook do not see them. For ssh:// addresses this Secret is mandatory and has to contain the ssh-privatekey key and also the known_hosts key, because the SSH client checks the key of the Git server strictly.
Run in an additional network
If the SSH server in a guest OS listens only in an additional sdn network, attach the run itself to that network with the connection.network field. The address of the virtual machine (VM) is not enough, because the pod network has no route into another L2 domain.
Troubleshooting a failed run
The playbook in this scenario fails on purpose. It shows where a run reports a failed task and where the full Ansible output is kept.
Scheduled run
The AnsibleRunSchedule resource creates runs on a cron schedule the way a CronJob resource creates Job objects. The name of each run contains the schedule name and the scheduled time.
Concurrency and history of a schedule
Four fields of a schedule define what happens if a run does not finish before the schedule triggers again, how late a run can start and how many runs to keep in the namespace.
Hosts specified by address
Hosts whose addresses DP does not know, for example physical servers and network appliances, are specified by address directly in the run manifest. How such targets differ from virtual machines is described in the Hosts specified by address section of the user guide.
Targets of type Hosts are available in commercial DP editions only. In DP Open, the API server rejects a manifest with such targets.
Variables of a run
Variables pass values to a playbook, so one playbook serves several environments without changes. You can write the value of a variable directly in the manifest as a string, a number, a list or a mapping.
Values from a Secret and a ConfigMap
You do not have to copy a password or a ready set of values into the manifest of a run. The valueFrom field takes the value of a variable from a key of a Secret or a ConfigMap, and the varsFiles field adds a whole YAML document with variables.