ANTS is a framework to manage and apply macOS and Linux host configurations using Ansible Pull.
The ANTS Framework is developed by the Client Services Team of the University of Basel IT Services and released under the GNU General Public License Version 3.
Ansible is a trademark of Red Hat, Inc..
The ANTS Framework consists of the following components:
Running ANTS with the default configuration will use ansible-pull to clone the ANTS playbook via https from a github repository and execute an ansible run.
By default, this will add a message of the day to your macOS or Linux host. Logs of all the runs are stored at /var/log/ants.
Also by default, ants will add github to your known_hosts file. This is important for later, when you want to enable git clone using ssh.
Besides the default configuration file in the ants_client package, ANTS will also look for a local configuration file at /etc/ants/ants.cfg.
You can use ants --show-config to list the current configuration and ants --initialize to generate a new configuration file at /ets/ants/ants.cfg.
Do not modify the default configuration file as it might be overwritten when updating ANTS.
Fork or duplicate our example playbook and change the client configuration to point to your repository. Update main.yml to assign different roles to your hosts.
You can use the default Ansible syntax. You can also use wildcards. Have a look at the Ansible documentation
Ansible-pull can clone a git repository using ssh. You can enable this by creating your own private playbook, adding ssh authentication and a read only ssh key to the repository. Configure ANTS to use that key.
By default, ANTS will look for a private key at /etc/ants/id_ants
You can generate a key with ssh-keygen -t rsa -b 4096 -N '' -C "ants client" -f /etc/ants/id_ants
By default, ANTS is configured to run with strict host key checking disabled and will add the host key for your repo to your known_hosts file. You should change this in production. To do so, add ssh_stricthostkeychecking = True to your ants.cfg
Ansible supports dynamic inventory scripts. (A json representation of hosts to group mappings.)
You can use scripts to tell ansible-pull which tasks to run on which host. You need an inventory source and a script that can read and return it in the correct format:
By default, ANTS will run a dummy script inventory_default that will just return your hostname belonging to a group named ants-common.
But we also provide inventory_ad which will connect to your Active Directory and return all groups your host is a member of. Just add your configuration to /etc/ants/ants.cfg. Note that read only rights for the Active Directory user are sufficient.
By using a dynamic inventory source, you can assign roles to a host using AD and let ANTS handle the configuration.
The groups in Active Directory must have the same names as the mappings and the variables you want to assign using Ansible. We recommend to keep the groups in a dedicated Organizational Unit to prevent naming collisions.
Nested groups with access restrictions are an easy way to offer rights delegation to other units in your organization.
Nothing. You just set up a configuration management that communicates savely over ssh using your AD and Github.
No additional infrastructure required.
Please find the source code documentation below. To contribute please file a Pull Request on GitHub.
Run ansible-pull with a set of defined parameters and log the content of these runs.
Search for a file in environment PATH and return first match or None
Read subprocess output and dispatch it to logger.
Run ansible-pull.
The ansible python api is provided as is and the core team reserve the right to push breakting changed.
Hence, we call the cli directly and do not attempt to work with the api.
Documentation: http://docs.ansible.com/ansible/dev_guide/developing_api.html
Default inventory script.
This is a dummy inventory script to bootstrap ants. It will return localhost and fqdn as members of the ants-common group.
These values can be used to assign roles in local.yml but using a dynamic inventory script like inventory_ad.py is the prefered way of running ants.
This script is an Ansible Dynamic Inventory script. It takes the host name of a client, searches for it in MS Active Directory and returns it’s groups. The groups are filtered by prefix and Active Directory Organizational Unit.
This script returns the group and hostname in an Ansible compatible JSON format. The script writes an offline cache file for later use if the Active Directory query succeeds. This cache is returned if the Active Directory query fails.
It always returns the common group for common tasks. It also returns the group common-ad-bound if the result comes from an online query rather than from the cache.
Connect to Active Directory and return the connection or None.
Return results in Ansible JSON syntax.
Ansible requirements are documented here: http://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html
Take the simple host name and return it’s distinguished name
Receive groups that the computer object is a member off. member:1.2.840.113556.1.4.1941:=%s is a special Active Directory OID that returns nested groups and not just the first level. The result is filtered by group prefix and Organizational Unit
Handle parsing of configuraiton file options.
Create directory
Use pwd and grp to get uid/gid. https://stackoverflow.com/questions/5994840/how-to-change-the-user-and-group-permissions-for-a-directory-by-name
Get configuration from command line and return ConfigParser opject
If no value is specified by the user, the value marked as example will be written set.
Only values that differ from the system defaults are written to the local config file.
Take and return a dict of values and prompt the user for a reply.
Handle logging.
Return logging object with handler and formatter.
Log play recap in a dedicated form.
Rollover old logfiles befor writing.
Read client status from recap log.
Status can have one of the following forms: * ok * changed * failed
We expect IndexError because play recap will be empty if no matching hosts were found. Client status will be set to failed in that case.
Status will also be set to failed of no log file could be found.
Rotate log files at the start of every ansible run
Keep track of ok/changed/failed on a per run basis. Hence, rotate them at the start of each run.
Code for rotation based on https://stackoverflow.com/questions/4654915/rotate-logfiles-each-time-the-application-is-started-python
Custom argparse actions and main argparse are defined here.
Print active git brunch to stdout and exit.
Print active git repo to stdout and exit.
Execute inventory script and exit.
Print repo version file content and exit.
Print ants status to stdout and exit.
Prompt user for configuration input and write local config file.
Print ants configuration to stdout and exit.
Parse and return command line parameters.
This function relies on the custom actions defined previousely. Custom actions will be called if the corresponding argument is entered on the command line.
Make argparse read strings and return bool values.
Source: https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse