Skip to content
lemano ansible export

lemano ansible export

Write an Ansible project from what Lemano last read on servers

Description

Write a ready-to-run Ansible project into DIR from each host's latest
generation: roles, a playbook (site.yml), an inventory and a README.
The hosts are the inventory's (-i, repeatable; without, Ansible's
configured inventory), narrowed by --limit as Ansible takes it. A host
must have been read before (lemano ansible discover).

The roles are grouped by function, in the order they run: package_sources
(sources, keys), packages (installed by hand), users (accounts, groups,
authorized keys, sudo rules), checkouts, files (other configuration files
changed or added), one role per service whose unit or drop-in was written
on the host, system (kernel settings, cron files, network mounts, swap
files),
ssh_server and firewall, last since they can cut the play's connection.
By default only what matters on a host is exported, as lemano
ansible check lists it as forgotten; --all exports every object. Files
the system writes are never exported.

With several hosts, what they all share stays in the role; what differs
goes to host_vars/HOST.yml and host_files/HOST/. Host names and fstab
always stay per host. The network configuration (netplan, interfaces,
NetworkManager connections) is never exported: it names the hardware and
addresses of one machine, and is listed under "Not exported".

The content of a file that may hold secrets (one that only some users
can read, or that holds keys, commands or sudo rules) is never written in
plain text: it becomes a variable for you to define, listed in the
README. With --with-secrets it is written as an Ansible Vault value,
encrypted with a password asked without echo or read from
--vault-password-file. Passwords of accounts are never exported.

Packages installed from local files, mounts of a local disk, and files
whose content Lemano does not keep, are listed in the README.

Exit codes: 0 the project was written; 7 a host could not be exported
(the others were); 2 a usage error, such as an --out folder that is not
empty; 1 other errors.

Synopsis

lemano ansible export --out DIR [-i INVENTORY]... [--limit PATTERN] [flags]

Examples

lemano ansible export --out ansible-project -i inventories/prod/hosts.yml
lemano ansible export --out ansible-project -i hosts.ini --limit web1
lemano ansible export --out ansible-project -i hosts.ini --with-secrets --vault-password-file .vault-pass

Flags

FlagTypeDefaultDescription
--accept-new-host-keypin the key of a host that has none pinned and is not in your known_hosts files (without it, such a host is refused)
--allexport every object, not only what matters on each host
-i, --inventorystringArrayan inventory, as Ansible takes it (repeatable)
--limitstringthe hosts to export, as ansible-playbook –limit takes it
--no-refreshexport each host’s latest generation without reading the host first (nothing is then taken for part of the system image)
--outstringthe folder to write the project into: new or empty
-o, --outputstringoutput format: json or yaml (default: a table for people)
--pin-versionspin each package to its installed version
--vault-idstringArraythe vault identity that decrypts the inventory, as ansible-playbook –vault-id takes it (repeatable)
--vault-password-filestringthe file holding the vault password: it decrypts the inventory, and with –with-secrets encrypts the secrets written
--with-secretswrite the content of files that may hold secrets as Ansible Vault values

Exit codes

See exit codes.

See also