Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <module> Add the module to this host in the inventory
host remove-module <module> Remove the module from this host in the inventory
host add-role <role> Add the role to this host in the inventory
host remove-role <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 <module> Add the module to this host in the inventory
host remove-module <module> Remove the module from this host in the inventory
host add-role <role> Add the role to this host in the inventory
host remove-role <role> Remove the role from this host in the inventory
host set-variable <variable> <value> Set a variable to some value on this host in the inventory
host unset-variable <variable> <value> 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?
Expand Down
42 changes: 35 additions & 7 deletions av
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ Commands:
list-roles List all available roles

Host actions:
host <host> [host...] Show attributes for the host(s)
host <host> add Add the host to the inventory
host <host> remove Remove the host from the inventory
host <host> add-module <module> Add the module to the host in the inventory
host <host> remove-module <module> Remove the module from the host in the inventory
host <host> add-role <role> Add the role to the host in the inventory
host <host> remove-role <role> Remove the role from the host in the inventory
host <host> [host...] Show attributes for the host(s)
host <host> add Add the host to the inventory
host <host> remove Remove the host from the inventory
host <host> add-module <module> Add the module to the host in the inventory
host <host> remove-module <module> Remove the module from the host in the inventory
host <host> add-role <role> Add the role to the host in the inventory
host <host> remove-role <role> Remove the role from the host in the inventory
host <host> set-variable <variable> <value> Set a variable to some value on this host in the inventory
host <host> unset-variable <variable> <value> Unset a variable to some value on this host in the inventory
EOF
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down