m.(A.TT)/er
ambit n 1. scope or extent 2. a sphere of action, expression, or influence
Friday 07/29/11 at 09:46:40 PM

The latest Ambit RPM is : ambit-2.0-40.noarch.rpm

The latest Ambit OSX Package is : ambit-2.0-40.zip

The latest Ambit Tar, Gzipped Source is : ambit-2.0-39.tgz

Ambit, at its simplest, uses Bash Brace Expansion to expand and list hostnames OR commands. First and foremost Ambit is meant to be a general purpose hostlist enumerator to be used by other applications or scripts. Additionally Ambit can be used to manage User Specific as well as System-Wide HostGroups. It can also be used to query Network HostGroups. Finally, Ambit is able to detect when it is expanding a command (rather than a host list), allowing for the command to be expanded and executed synchronously. This means Ambit can expand and run just about anything on the command line and usually works in places where Bash Brace Expansion might fail.

Contents

Define Hosts Wherever

Ambit allows for hosts to be enumerated from a number of different places including directly on the command line (via an Ambit expandable string), a file in the current working directory ($PWD), a file whose path is specified, user pre-defined hostgroups, system pre-defined hostgroups and network definted hostgroups.

Hosts On The Command Line

Ambit will accept an expandable string on the command line and expand that string into either hosts or hostgroups. If any part of a string expands to a pre-existing HostGroup, Ambit will then enumerate the HostGroup along with any other hosts/HostGroups that may also result from expansion.

$ ambit ns[1..5].[apple,google,twitter,facebook].com
ns1.apple.com
ns1.facebook.com
ns1.google.com
ns1.twitter.com
ns2.apple.com
ns2.facebook.com
ns2.google.com
ns2.twitter.com
ns3.apple.com
ns3.facebook.com
ns3.google.com
ns3.twitter.com
ns4.apple.com
ns4.facebook.com
ns4.google.com
ns4.twitter.com
ns5.apple.com
ns5.facebook.com
ns5.google.com
ns5.twitter.com

File With Hosts In Current Working Directory

If a file happens to be in the current working directory ($PWD) of the user running Ambit containing an expandable string (or strings) or hostnames, it can be passed to Ambit as an argument for expansion or enumeration.

$ echo -e "ns1.a.tt\nns2.a.tt\nns3.a.tt\n[1..3].a.tt" > hosts.txt

$ cat hosts.txt 
ns1.a.tt
ns2.a.tt
ns3.a.tt
[1..3].a.tt

$ ambit hosts.txt
1.a.tt
2.a.tt
3.a.tt
ns1.a.tt
ns2.a.tt
ns3.a.tt

Full Path To File Containing Hosts

Ambit will accept the full path to a file with Ambit expandable strings or hostnames that it will enumerate.

$ echo -e "web[1..5].a.tt\nns1.a.tt\nns3.a.tt\n[1..3].a.tt" > /usr/tmp/hosts.txt

$ cat /usr/tmp/hosts.txt
web[1..5].a.tt
ns1.a.tt
ns3.a.tt
[1..3].a.tt

$ ambit /usr/tmp/hosts.txt
1.a.tt
2.a.tt
3.a.tt
ns1.a.tt
ns3.a.tt
web1.a.tt
web2.a.tt
web3.a.tt
web4.a.tt
web5.a.tt

User Specific HostGroups

Ambit will enumerate Ambit expandable strings or hostnames by a designated name created with 'ambit create hostgroup' or manually and located in the directory $HOME/.ambit/hosts.

$ ambit create hostgroup
HostGroup Name : myhosts
HostGroup Summary : Example User HostGroup For Online Documentation
Enter Hostnames Below [Ctrl-d to End]: 
web[1..5].a.tt

$ ambit list hostgroups

User HostGroup[s]
-----------------
myhosts:   Example User HostGroup For Online Documentation 

$ ambit myhosts
web1.a.tt
web2.a.tt
web3.a.tt
web4.a.tt
web5.a.tt

System-Wide HostGroups

Ambit will enumerate Ambit expandable strings or hostnames by a designated name created as root via 'sudo ambit create hostgroup' or manually and located in the directory /var/ambit/hosts. All users on a given system will be able to reference these groups.

$ sudo ambit create hostgroup
HostGroup Name : syshosts
HostGroup Summary : Example System-wide HostGroup For Online Documentation
Enter Hostnames Below [Ctrl-d to End]: 
ns1.yahoo.com
ns2.yahoo.com
ns3.yahoo.com
ns4.yahoo.com
ns5.yahoo.com
ns6.yahoo.com

$ ambit list hostgroups

System HostGroup[s]
-------------------
syshosts:   Example System-wide HostGroup For Online Documentation 

User HostGroup[s]
-----------------
myhosts:   Example User HostGroup For Online Documentation 

$ ambit syshosts
ns1.yahoo.com
ns2.yahoo.com
ns3.yahoo.com
ns4.yahoo.com
ns5.yahoo.com
ns6.yahoo.com

Network HostGroups

Ambit will enumerate Ambit expandable strings stored in DNS TXT records at a domain specified in the Domain="" option. For example, the following Network HostGroup has been setup for enumerating m.a.tt/er's Yum servers from pretty much anywhere on the Internet:

$ host -t txt yum.a.tt
yum.a.tt descriptive text "[1..3].a.tt"

Setting Ambit domain option to a.tt results in the following when listing HostGroups and actually enumerating the 'yum' HostGroup:

$ ambit ed opt Domain
Updating Option : Domain
Current Value   : 
Enter New Value : a.tt
Domain="a.tt"

$ ambit ls hgs

Network HostGroup[s]
--------------------
yum:     "[1..3].a.tt"

System HostGroup[s]
-------------------
syshosts:   Example System-wide HostGroup For Online Documentation 

User HostGroup[s]
-----------------
myhosts:     Example User HostGroup For Online Documentation 

$ ambit yum
1.a.tt
2.a.tt
3.a.tt

HostGroup Controls

Many of the examples above give a pretty good idea of Ambit's new functionality when it comes to managing and making use of defined sets of hosts. Ambit provides the means for creating, editing, and removing both System and User HostGroups. Ambit also provides the ability to list User, System and Network HostGroups.

ambit list hostgroups

List all accessible User, System and Network HostGroups. Name and Description are displayed:

2 $ ambit list hostgroups

Network HostGroup[s]
--------------------
all:     "[1..3].a.tt"
apache:  "[1..3].a.tt"
att:     "[1..3].a.tt"
svn:     "2.a.tt"
yum:     "[1..3].a.tt"

System HostGroup[s]
-------------------
sysprod:   System Wide Group of Production Hosts 

User HostGroup[s]
-----------------
down:      Honoring System Wide Down Hosts List 
gfonky:    Gerald's World 
results:   2011-07-12 10:36:02 massh all bombed grep Marschall /etc/passwd

ambit create hostgroup

Creating a new User or System HostGroup is as simple as following a short dialogue where the user is prompted for the name, description and entries of the new HostGroup. Entries can be listed one host per line or by one or more Ambit expandable strings. Ambit is fairly flexible and will accept alternating entries of single hosts and expandable strings. In the event that a large number of hosts are being imported into a new group, Ambit's dialogue is able to deal with pasting large numbers of hosts or entries. Alternatively those hosts can be redirected to the HostGroup file after it has been established via the dialogue. User HostGroup definitions are located at $HOME/.ambit/hosts, while System HostGroup definitions are stored at /var/ambit/hosts. System HostGroups can only be created by running Ambit with root privileges.

$ ambit create hostgroup
HostGroup Name : colo1
HostGroup Summary : Colocation Site 1 - All Hosts
Enter Hostnames Below [Ctrl-d to End]: 
1www[1..10].radsite.com
1app[1..10].radsite.com
1mdb[1..5].radsite.com

$ grep colo1 <(ambit list hostgroups)       
colo1:     Colocation Site 1 - All Hosts

$ ambit colo1
1app1.radsite.com
1app10.radsite.com
1app2.radsite.com
1app3.radsite.com
1app4.radsite.com
1app5.radsite.com
1app6.radsite.com
1app7.radsite.com
1app8.radsite.com
1app9.radsite.com
1mdb1.radsite.com
1mdb2.radsite.com
1mdb3.radsite.com
1mdb4.radsite.com
1mdb5.radsite.com
1www1.radsite.com
1www10.radsite.com
1www2.radsite.com
1www3.radsite.com
1www4.radsite.com
1www5.radsite.com
1www6.radsite.com
1www7.radsite.com
1www8.radsite.com
1www9.radsite.com

ambit remove hostgroup [HostGroup]

This is very straight forward - If you want to nuke a HostGroup it's as simple as:

$ ambit remove hostgroup colo1
HostGroup 'colo1' Has Been Deleted

ambit edit hostgroup [HostGroup]

The edit option will open the specified HostGroup in vi for your editing pleasure. Be sure and leave the top 3 lines as they are if you want to insure the HostGroup you are editing will be listed when running ambit list hostgroups.


$ sudo ambit edit hostgroup sysprod

#
# Summary - System Wide Group of Production Hosts
#
prod[1..40].a.tt
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"/var/ambit/hosts/sysprod" 4L, 72C

Option Controls

In order to simplify Ambit and Massh on the command line it became necessary to create functionality that allowed for the listing and editing of nearly all useful runtime options. Ambit's Option Controls provide a simple interface for the relatively few options that are currently editable in Ambit:

ambit list options

Listing Ambits options will present both the System defaults and any User overrides for the defaults:

$ ambit list options

System Options
--------------
Debug="no"
Random="$RANDOM"
Domain=""

User Options
------------
Domain="a.tt"

ambit edit option [OptionName]

Editing options really amounts to either overriding a System default or removing an override. Editing the System defaults (should be pretty rare) can be done by directly editing /etc/ambit/ambit.conf.

$ ambit edit option Random
Updating Option : Random
Current Value   : $RANDOM
Enter New Value : $(mcookie)
Random="$(mcookie)"

$ ambit list options

System Options
--------------
Debug="no"
Random="$RANDOM"
Domain=""

User Options
------------
Domain="a.tt"
Debug="no"
Random="$(mcookie)"

The example above overrides the System default for generating random string output for the current user only (neither of the above means is great for avoiding race conditions; $(mcookie) being the lesser of two evils).

Short Commands

Ambit supports an abbreviated subcommand syntax:

Special Hostgroup: down

There is a special System HostGroup called 'down' (/var/ambit/hosts/down) that is installed and left empty by default. This group is meant to provide a dynamic, near realtime listing of hosts that have been determined to be unreachable from the local host for one reason or another. Reasons can range from, a host or hosts in 'down' have failed specific monitoring check or failed the last periodic ping check or someone with root privileges has decided that it is down. If a host happens to be currently listed in the System HostGroup 'down' AND a user has a User HostGroup named down ($HOME/.ambit/hosts/down) Ambit will omit the host from all results for that user. In other words, users can choose whether they want to honor the current list of unreachable hosts according the local host. To do so they simple have to create the HostGroup down with no hosts listed. The existence of this group tells Ambit to honor the System HostGroup 'down'.

To demonstrate how this works the first step is to create the System HostGroup 'down' containing a single host:

$ sudo ambit create hostgroup
HostGroup Name : down
HostGroup Summary : System Wide Unreachable Hosts
Enter Hostnames Below [Ctrl-d to End]:
test1.mydomain.org

$ ambit list hostgroups | grep down
down:       System Wide Unreachable Hosts

$ ambit down
test1.mydomain.org

Next step is to create a test User HostGroup (mydomain) that will eventually have some of its hosts excluded from Ambit results:

$ ambit create hostgroup
HostGroup Name : mydomain
HostGroup Summary : Production mydomain.org Servers
Enter Hostnames Below [Ctrl-d to End]:
test[1..12].mydomain.org

$ ambit mydomain
test1.mydomain.org
test10.mydomain.org
test11.mydomain.org
test12.mydomain.org
test2.mydomain.org
test3.mydomain.org
test4.mydomain.org
test5.mydomain.org
test6.mydomain.org
test7.mydomain.org
test8.mydomain.org
test9.mydomain.org

Now to create the User HostGroup 'down' and enumerate our test HostGroup (mydomain) to see if Ambit excludes the host (test1.mydomain.org) listed in the System HostGroup 'down'.

$ ambit create hostgroup
HostGroup Name : down
HostGroup Summary : Honoring System HostGroup 'down'
Enter Hostnames Below [Ctrl-d to End]:

$ ambit list hostgroups

System HostGroups
------------------
down:   System Wide Unreachable Hosts

User HostGroups
----------------
mydomain:   Production mydomain.org Servers
down:       Honoring System HostGroup 'down'

$ ambit mydomain
test10.mydomain.org
test11.mydomain.org
test12.mydomain.org
test2.mydomain.org
test3.mydomain.org
test4.mydomain.org
test5.mydomain.org
test6.mydomain.org
test7.mydomain.org
test8.mydomain.org
test9.mydomain.org

Let's add some more hosts the the System HostGroup 'down' and re-list the test HostGroup (mydomain):

$ sudo ambit edit hostgroup down

#
# Summary - System Wide Unreachable Hosts
#
test1.mydomain.org
test10.mydomain.org
test11.mydomain.org
test12.mydomain.org

$ ambit mydomain
test2.mydomain.org
test3.mydomain.org
test4.mydomain.org
test5.mydomain.org
test6.mydomain.org
test7.mydomain.org
test8.mydomain.org
test9.mydomain.org

Works as advertised.

This site will always use valid XHTML and valid CSS.

© AfterTheTweet.com 2014