diff --git a/README.md b/README.md index 4030267..365c9c0 100644 --- a/README.md +++ b/README.md @@ -241,13 +241,15 @@ Commands: resume Resume periodic runs after a pause Host actions: - host add Add the current host to the inventory - host add-module Add the module to this host in the inventory - host remove-module Remove the module from this host in the inventory - host add-role Add the role to this host in the inventory - host remove-role Remove the role from this host in the inventory - host diff See what has changed in the local inventory - host push Push local inventory changes up to the git origin + host add Add the current host to the inventory + host add-module Add the module to this host in the inventory + host remove-module Remove the module from this host in the inventory + host add-role Add the role to this host in the inventory + host remove-role Remove the role from this host in the inventory + host set-variable Set a variable to some value on this host in the inventory + host unset-variable Unset a variable to some value on this host in the inventory + host diff See what has changed in the local inventory + host push Push local inventory changes up to the git origin ``` ## Why Bash? diff --git a/av b/av index d052534..f0be819 100755 --- a/av +++ b/av @@ -59,13 +59,15 @@ Commands: list-roles List all available roles Host actions: - host [host...] Show attributes for the host(s) - host add Add the host to the inventory - host remove Remove the host from the inventory - host add-module Add the module to the host in the inventory - host remove-module Remove the module from the host in the inventory - host add-role Add the role to the host in the inventory - host remove-role Remove the role from the host in the inventory + host [host...] Show attributes for the host(s) + host add Add the host to the inventory + host remove Remove the host from the inventory + host add-module Add the module to the host in the inventory + host remove-module Remove the module from the host in the inventory + host add-role Add the role to the host in the inventory + host remove-role Remove the role from the host in the inventory + host set-variable Set a variable to some value on this host in the inventory + host unset-variable Unset a variable to some value on this host in the inventory EOF } @@ -299,6 +301,26 @@ function host_add_role { echo $role >> $roles_file } +function host_set_variable { + local host=$1 + read variable value<<<$2 + vars_file=$inventory_dir/hosts/$host/variables + + mkdir -p $inventory_dir/hosts/$host + touch $vars_file + echo "$(grep -v ^$variable= $vars_file)\n$variable='$value'" > $vars_file +} + +function host_unset_variable { + local host=$1 + local variable=$2 + vars_file=$inventory_dir/hosts/$host/variables + + mkdir -p $inventory_dir/hosts/$host + touch $vars_file + echo "$(grep -v ^$variable=)" > $vars_file +} + function check_roles { for role in $(ls -1 $inventory_dir/roles); do if [[ ! -e $inventory_dir/roles/$role/modules ]]; then @@ -469,6 +491,12 @@ case $command in remove-role) host_remove_role $host $subcommand_arg ;; + set-variable) + host_set_variable $host $subcommand_arg + ;; + unset-variable) + host_unset_variable $host $subcommand_arg + ;; *) for host in $command_arg; do entry=$(host_entry $host)