From f2c2786a1435df62aa7a459480c06e5c9a2da833 Mon Sep 17 00:00:00 2001 From: Tim Bielawa Date: Mon, 5 Mar 2012 16:06:02 -0500 Subject: [PATCH] Update constants.py to pull module path and the hosts file from the environment (ANSIBLE_{LIBRARY,HOSTS}) if defined. Update manpages to represent this. Also update the env-setup script to set ANSIBLE_{LIBRARY,HOSTS}. --- docs/man/man1/ansible.1.asciidoc | 16 +++++++++++++--- docs/man/man5/ansible-modules.5.asciidoc | 13 ++++++++++--- docs/man/man5/ansible-playbook.5.asciidoc | 16 +++++++++++----- hacking/env-setup | 10 ++++++++++ lib/ansible/constants.py | 10 +++++++--- 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/docs/man/man1/ansible.1.asciidoc b/docs/man/man1/ansible.1.asciidoc index 27ca985b086..047c4adcf15 100644 --- a/docs/man/man1/ansible.1.asciidoc +++ b/docs/man/man1/ansible.1.asciidoc @@ -25,7 +25,7 @@ SSH. ARGUMENTS --------- -*hostspec* +*host-pattern*:: A name of a group in the inventory file, a shell-like glob selecting hosts in inventory file, or any combination of the two seperated by semicolons. @@ -75,6 +75,16 @@ FILES /usr/share/ansible -- Default module library +ENVIRONMENT +----------- + +The following environment variables may specified. + +ANSIBLE_HOSTS -- Override the default ansible hosts file + +ANSIBLE_LIBRARY -- Override the default ansible module library path + + AUTHOR ------ @@ -95,7 +105,7 @@ SEE ALSO Ansible home page: -*ansible-modules*(5), +*ansible-modules*(5) -*ansible-playbook*(5), +*ansible-playbook*(5) diff --git a/docs/man/man5/ansible-modules.5.asciidoc b/docs/man/man5/ansible-modules.5.asciidoc index 760db571d0f..afdd461b636 100644 --- a/docs/man/man5/ansible-modules.5.asciidoc +++ b/docs/man/man5/ansible-modules.5.asciidoc @@ -3,7 +3,7 @@ ansible-modules(5) :doctype:manpage :man source: Ansible-modules :man version: 0.0.1 -:man manual: System administration commands +:man manual: Ansible NAME @@ -23,7 +23,7 @@ IDEMPOTENCE Most modules other than command are idempotent, meaning they will seek to avoid changes unless a change needs to be made. When using ansible playbooks, these modules can -trigger change events, as described in ansible-playbooks (5). +trigger change events, as described in *ansible-playbooks*(5). Unless otherwise noted, all modules support change hooks. @@ -148,7 +148,7 @@ setup Writes a JSON file containing key/value data, for use in templating. Call this once before using the template modules, usually as the very -first step in your playbook. +first step in your playbook. If facter or ohai are installed, variables from these programs will also be snapshotted into the JSON file for usage in templating. These variables @@ -212,6 +212,13 @@ To support change hooks, modules should return hashes, with a changed: True/Fals element at the top level. Modules can also choose to indicate a failure scenario by returning a top level 'failure' element with a True value. + +ENVIRONMENT +----------- + +ANSIBLE_LIBRARY -- Override the default ansible module library path + + AUTHOR ------ diff --git a/docs/man/man5/ansible-playbook.5.asciidoc b/docs/man/man5/ansible-playbook.5.asciidoc index 55726295667..9bbcf9a9f7b 100644 --- a/docs/man/man5/ansible-playbook.5.asciidoc +++ b/docs/man/man5/ansible-playbook.5.asciidoc @@ -3,7 +3,7 @@ ansible-modules(5) :doctype:manpage :man source: Ansible-playbook :man version: 0.0.1 -:man manual: System administration commands +:man manual: Ansible NAME @@ -28,13 +28,13 @@ Playbooks are written in YAML. EXAMPLE ------- -see +See: -https://github.com/mpdehaan/ansible/blob/master/examples/playbook.yml +- https://github.com/mpdehaan/ansible/blob/master/examples/playbook.yml -https://github.com/mpdehaan/ansible/blob/master/examples/base.yml +- https://github.com/mpdehaan/ansible/blob/master/examples/base.yml -https://github.com/mpdehaan/ansible/blob/master/examples/handlers.yml +- https://github.com/mpdehaan/ansible/blob/master/examples/handlers.yml WHAT THE EXAMPLE MEANS ----------------------- @@ -100,6 +100,12 @@ If a host has a failure, the host will be ignored for the remainder of the playbook execution. +ENVIRONMENT +----------- + +ANSIBLE_LIBRARY -- Override the default ansible module library path + + AUTHOR ------ diff --git a/hacking/env-setup b/hacking/env-setup index 1f4af4e1a26..aba7af76a14 100755 --- a/hacking/env-setup +++ b/hacking/env-setup @@ -2,10 +2,20 @@ PREFIX_PYTHONPATH="`pwd`/lib/ansible:`pwd`/lib" PREFIX_PATH="`pwd`/bin" PREFIX_MANPATH="`pwd`/docs/man" +PREFIX_ANS_LIBRARY="`pwd`/library" +PREFIX_ANS_HOSTS="`pwd`/examples/ansible_hosts" echo "Prefixing PYTHONPATH with $PREFIX_PYTHONPATH" export PYTHONPATH=$PREFIX_PYTHONPATH:$PYTHONPATH + echo "Prefixing PATH with $PREFIX_PATH" export PATH=$PREFIX_PATH:$PATH + echo "Prefixing MANPATH with $PREFIX_MANPATH" export MANPATH=$PREFIX_MANPATH:$MANPATH + +echo "Setting ANSIBLE_LIBRARY to ${PREFIX_ANS_LIBRARY}" +export ANSIBLE_LIBRARY=${PREFIX_ANS_LIBRARY} + +echo "Setting ANSIBLE_HOSTS to ${PREFIX_ANS_HOSTS}" +export ANSIBLE_HOSTS=${PREFIX_ANS_HOSTS} diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index fde6a503635..3004d1a104b 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -16,9 +16,14 @@ # along with Ansible. If not, see . # +import os + + # control side (aka 'overlord') -DEFAULT_HOST_LIST = '/etc/ansible/hosts' -DEFAULT_MODULE_PATH = '/usr/share/ansible' +DEFAULT_HOST_LIST = os.environ.get('ANSIBLE_HOSTS', + '/etc/ansible/hosts') +DEFAULT_MODULE_PATH = os.environ.get('ANSIBLE_LIBRARY', + '/usr/share/ansible') DEFAULT_MODULE_NAME = 'command' DEFAULT_PATTERN = '*' DEFAULT_FORKS = 5 @@ -26,4 +31,3 @@ DEFAULT_MODULE_ARGS = '' DEFAULT_TIMEOUT = 10 DEFAULT_REMOTE_USER = 'root' DEFAULT_REMOTE_PASS = None -