Graph-IT

push.php.json

The push.php-file is the interface to the user. It allows to:

and a few other things.

Usage

push.php

Usage:
  command [options] [arguments]

Options:
  -h, --help  Display this help message

Available commands:
  help                       Displays help for a command
  list                       Lists commands
 configuration
  configuration:allgenerate  Generate configuration for all associated templates/confs (and copy non-template files) for host(s) from inventory
  configuration:diffsync     Diff or sync configuration from local directories to remote host(s) from inventory
  configuration:generate     Generate configuration from templates (and copy non-template files) for host(s) from inventory
 dynamic
  dynamic:acquire            Acquire dynamic data from host(s) from inventory
  dynamic:show               List and show dynamic data for host(s) from the inventory
 inventory
  inventory:add              Add a host to the inventory
  inventory:check            Check IP attribute for host(s) from the inventory
  inventory:list             List and show attributes for host(s) from the inventory
  inventory:remove           Remove a host from the inventory
  inventory:set              Set attribute for a host in the inventory
 push
  push:active                Shows hosts that react to a 'ping'
  push:command               Executes for the given hosts the given template command
  push:openssh               Shows hosts with open ssh port
  push:poweroff              Powers down hosts with no logged in users or lists the logged in users
  push:reboot                Reboots hosts with no logged in users or lists the logged in users
  push:wakeonlan             Wake on Lan

Note that all commands are prefix-unique and that this allows to call a command in a faster way. For example instead of using:

Workflow

The general work flow when using push to handle host configuration files is to:

  1. Create/Update the network.json-file by hand if need be. This is the case whenever a new network host group is added. (see: network.json)
  2. Create/Update the inventory.json-file using the inventory:xxx-commands of push. (see: inventory.json and push.php).
  3. In case no dynamic data for the host exists, collect the dynamic data (/etc/network/interfaces and /etc/fstab) using dynamic:acquire. (see: push.php)
  4. Generate the files which need to be synched to the host using the configuration:xxx-commands of push. (see: push.php)
  5. Compare the generated configuration files of a host against the existing configuration using the configuration:diffsync-command of push. (see: push.php)
  6. Copy/Apply the newly generated configuration files to the host using the configuration:diffsync-command of push. (see: push.php)

Commands

Here's what each of the command is used for.

help

The help command displays help for a given command.

Usage

push.php help [options] [--] [<command_name>]

Calling

list-command

List the known commands optionally in a specific format and only for a given namespace.

Usage
push.php list [--raw] [--format FORMAT] [--] [<namespace>]

configuration:allgenerate-command

The configuration:allgenerate-command is used to generate the configuration files for a given host, or each host from a given group, and all the templates the host is associated to.

Usage
push.php configuration:allgenerate [-c|--clear] [--] <templates folder> <target> <group>

Calling

To be on the save side of things, it is adviced to always use the -c-parameter together with the configuration:generateall command to make sure no lingering old files are accidentally pushed to a host.

configuration:diffsync-command

The configuration:diffsync-command is used to compare either compare the content of a folder agains a remote folder or push/synchronize a given folder to a target host (or hosts inside a group).

Usage
push.php configuration:diffsync [-s|--sync] [--] <source> <target> <group>

Calling

configuration:generate-command

The configuration:generate-command is used to generate the configuration files of a single template for a host or a group of hosts. Calling this command with different templates allows to combine multiple templates. Note that this also allows to generate configuration files for templates which are normally not associated to a host. When adding a new client to the inventory this also allows to just update the DHCP and/or DNS configuration of a server without having to care about any other configuration. (see: 'Server/Rechner hinzufügen')

Usage
push.php configuration:generate [-c|--clear] [--] <source> <target> <group>

Calling

dynamic:acquire-command

The `dynamic:acquire-command is ment to aquire some host specific data from the target host which will be saved inside the tmp/dynamic.json-file and thus be available during processing of the templates.

Usage
push.php dynamic:acquire <group> <attributes> (<attributes>)...

Calling

Note: When collecting fstab-data all entries from the fstab of the host will be collected. Thus one needs to check that only the wanted entries are stored inside the tmp/dynamic.json-file. Typically only entries which map to physical devices are wanted. Mounting of network shares or similar should be covered through templates and not be part of the dynamic.json-file.

dynamic:show-command

Shows all or parts of the collected dynamic data for a host or a group of hosts.

Usage
push.php dynamic:show <group> [<attributes>]...

Calling

inventory:add-command

Adds a new host entry to the inventory, but can also be used to associate the host with a group.

Usage
push.php inventory:add [-m|--mac MAC] [-g|--group GROUP] [--] <name>

Calling

inventory:check-command

Checks whether a host or all hosts of a group have an IP and whether its 'ip4'-value inside the inventory.json matches the ip it should have based on it's name (and hostgroup association).

Usage
inventory:check [-r|--repair] [--] <group>

Calling

inventory:list-command

List attributes inside the inventory for a host or all hosts associated to a group.

Usage
push.php inventory:list [-a|--attribute ATTRIBUTE] [-A|--all] [--] <group>

Calling

A typical usage example for this is when a new host should be added but one doesn't know the name that was used for a the last host in the targeta hostgroup. So when adding a new PC we would first call push.php i:l workstations to see which names are already taken. With pc20 being the last workstation inside the inventory we would name the new workstation pc21.

inventory:remove-command

Removes a given host from the inventory. Note that there is no saveguard so only use this if you really want to remove a host from the inventory. This will not change the content of the dynamic.json-file.

Usage
push.php inventory:remove <name>

Calling

inventory:set-command

Set a an attribut for a host.

Usage
push.php inventory:set [-a|--array] [-c|--clear] [-r|--remove] [--] <name> <attribute> [<values>]...

Calling

To keep things simple always use '-a|--array' when dealing with arrays.

push:active-command

Shows hosts that react to a 'ping', which is a decent indicator to determine whether the host is active/online or not.

Usage
push.php push:active <group>

Calling

push:command-command

Call a specific command on a host or group.

Usage
push.php push:command <group> <template>

Note that this will show the output of the called command, but it does not offer any additional interaction with the host. So you will be stuck when a command requires additional user input.

Calling

Note that the template-command by default will be called as the current user (typically root), if you want to call it as another user you need to adjust the template-call to execute your command as another user. In example by using something like sudo -u <remoteuser> sh -c <command> as template-call.

push:openssh-command

Checks whether the open ssh port (22) is open on the host/group. Since most non-pcs to not support ssh and consequentyl don't have an open ssh port you might want to use push:active instead to determine if those hosts are active.

Usage
push.php push:openssh <group>

Calling

push:poweroff-command

Turns off a host or group of hosts with no logged in users or lists the logged in users.

Usage:
push.php push:poweroff <group>

Calling

push:reboot-command

Reboots a host or group of hosts with no logged in users or lists the logged in users.

Usage
push.php push:reboot <group>

Calling

push:wakeonlan-command

Sends a wake-on-lan magic ethernet package to the host or groups of hosts.

Usage
push.php push:wakeonlan <group>

Calling

General usage remarks

Here are some general remarks for using the push.php executable.

  1. Always make sure you compare a configuration against the current state before sending it to a server.
  2. Normally old genmerated configurations should be cleared before generateing new ones to avoid unwanted old files to be synchonized.
  3. Make sure to read 'Server/Rechner hinzufügen' when adding new clients or servers.
  4. Before generating a configuration for a new host make sure you collected it's dynamic data and added everything needed for it to the inventory.
  5. Make sure you can passwordless ssh to the target host before acquiring dynamic data, pushing or comparing a configuration. (i.e. use ssh-copy-key <hostIP> on the server)