Skip to content

lemano ansible discover

Runs lemano discover on the hosts of an Ansible inventory, reached with the inventory’s own settings, with no target file to keep. It is what a timer runs between playbook runs when the targets were made by recording the runs.

lemano ansible discover [-i INVENTORY]... [HOST]... [lemano discover flags]

The flags and examples of the command are also on its generated page.

What it does

  1. Reads the inventory with ansible-inventory --list: the -i values (repeatable, as Ansible takes them), or, without -i, Ansible’s own configured inventory (inventory in ansible.cfg, or ANSIBLE_INVENTORY), exactly as ansible-playbook would find it.
  2. Builds a target file for each host in a private temporary folder (mode 700, files 600, removed afterwards), with the same mapping as lemano ansible import: connection settings and password references from the inventory; name, labels and discovery settings from the host’s Lemano target when it has one. A host with no target gets one.
  3. Checks host keys: a host Lemano has never pinned is checked against your known_hosts files when they have it. A host that neither has is refused: reason HostKeyUnknown, exit code 4, with its fingerprint; the other hosts are read all the same. Check the fingerprint with the host’s administrator, then give --accept-new-host-key to pin it. A changed key is always refused. (Recording a playbook run pins on first sight instead, since a run cannot stop to ask; see record.)
  4. Runs lemano discover -f FOLDER from the folder of this program, with the target names and every other flag you gave. Its output, -o json and exit codes are this command’s.

With HOST names (inventory names), only those hosts are read; with --limit PATTERN, the hosts the pattern selects, as Ansible selects them (groups, !, &, wildcards): the pattern is given to ansible-inventory --limit. Without either, every host of the inventory. Hosts that cannot be read (not reached over SSH, a value a target cannot hold) are named on standard error.

If there is no store yet, one is created, as lemano init does, and the command says where its key is.

Flags

FlagMeaning
-i, --inventoryAn inventory source, as Ansible takes it. Repeatable.
--limitAn Ansible host pattern that selects the hosts. Only the long form: -l is lemano’s label selector.
--vault-id, --vault-password-fileWhere the vault password is, as ansible-playbook takes them. Repeatable. Passed to every Ansible command this command starts, to read the inventory (a vaulted group_vars file, for example), and, in ANSIBLE_VAULT_IDENTITY_LIST (after the identities ansible.cfg already lists), to every Ansible process lemano discover starts in turn: so a login or sudo password kept in the vault (ansible: references) is read with the same password. Paths are made absolute. A value with a comma is refused (exit 2). ANSIBLE_VAULT_PASSWORD_FILE and ansible.cfg still apply, as for ansible-playbook; they are what a later plain lemano discover or a timer uses. They are not passed on to lemano discover as flags.
-J, --ask-vault-passAsk for the vault password once, on the terminal, without echo, before anything starts. See Asking for the vault password. Refused (exit 2) without a terminal. --vault-id LABEL@prompt is refused: use this option.
-fRefused: the target files are built from the inventory. Run lemano discover -f for your own files.
any otherPassed to lemano discover, for example -o json, --detailed-exitcode, --parallel.

Asking for the vault password

With -J (--ask-vault-pass) the password is read once, on the controlling terminal, without echo. It is never on a command line and in no file: Lemano keeps it in the environment of the processes it starts and gives Ansible a small script, in a private folder removed when the command ends, that prints it from there. While those processes run, the password is readable by the same user and by root, as any environment is; and a task of a playbook that runs on the controller (check runs your playbook) runs with that environment. Without a terminal the option is refused with exit code 2: give --vault-password-file. -J works the same with revert, end-trial and check.

A later plain lemano discover, and a timer, read the vault password the way Ansible does for any run: from vault_password_file in ansible.cfg or ANSIBLE_VAULT_PASSWORD_FILE. Ansible reads a relative path in vault_identity_list from the folder it runs in, not from the folder of ansible.cfg; this command makes such a path absolute from the folder you run it in, but a timer runs elsewhere, so give full paths there.

Example

$ lemano ansible discover -i inventories/prod/hosts.yml

A systemd timer or a cron line can run it every hour; see Scheduling.