Permalink
Browse files

cleanup example config file + Squashed commit of the following:

commit c36b66dc952dfff91043ecbca56cf3f1f8f00703
Merge: 240d7bf f4cf934
Author: Michael DeHaan <michael@ansibleworks.com>
Date:   Tue Jun 18 13:04:51 2013 -0400

    Merge branch 'unevaluated-vars' of git://github.com/lorin/ansible into lorin_undefined

    Conflicts:
    	lib/ansible/runner/__init__.py

commit f4cf934
Merge: 2531440 07a1365
Author: Lorin Hochstein <lorin@nimbisservices.com>
Date:   Thu Jun 6 11:07:41 2013 -0400

    Merge branch 'devel' into unevaluated-vars

commit 2531440
Author: Lorin Hochstein <lorin@nimbisservices.com>
Date:   Thu Jun 6 11:06:37 2013 -0400

    Fail template from file on undefined vars

    If config option is set, raise an exception if templating from a
    file and a variable is undefined.

commit aecb71d
Author: Lorin Hochstein <lorin@nimbisservices.com>
Date:   Wed Jun 5 17:12:12 2013 -0400

    Add fail_on_undefined flag

    Add a fail_on_undefined flag to the template and template_from_string methods.

    If this flag is true, then re-raise the ninja2.excpetions.UndefinedError instead of
    swallowing it.

commit cbb1808
Merge: d4bbf49 41425fb
Author: Lorin Hochstein <lorin@nimbisservices.com>
Date:   Wed Jun 5 16:14:12 2013 -0400

    Merge branch 'devel' into unevaluated-vars

commit d4bbf49
Author: Lorin Hochstein <lorin@nimbisservices.com>
Date:   Mon Jun 3 19:46:13 2013 -0400

    template: Raise UndefinedError exception

    In template_from_string, raise an undefined error if it occurs.

    Have the caller catch it and throw an AnsibleUndefinedVariable

commit c947802
Merge: 8d919d6 be33bcf
Author: Lorin Hochstein <lorin@nimbisservices.com>
Date:   Mon Jun 3 10:09:43 2013 -0400

    Merge branch 'devel' into unevaluated-vars

commit 8d919d6
Merge: 0f68ad8 b8630d2
Author: Lorin Hochstein <lorin@nimbisservices.com>
Date:   Thu May 30 16:27:48 2013 -0400

    Merge branch 'devel' into unevaluated-vars

commit 0f68ad8
Author: Lorin Hochstein <lorin@nimbisservices.com>
Date:   Thu May 30 14:32:03 2013 -0400

    Optionally fail task on undefined variables

    This patch introduces a new configuration option called
    error_on_undefined_vars, which defaults to false.

    If this option is set to true, then a task which has unevaluated
    variables in its arguments will fail instead of running. Output looks
    like this:

        TASK: [set rabbitmq password] *************************************************
        fatal: [10.20.0.7] => Undefined variables: rabbitmq_user, rabbitmq_password
  • Loading branch information...
Michael DeHaan
Michael DeHaan committed Jun 18, 2013
1 parent 240d7bf commit 637983cf31a6de0ff1e02a130bb95acc38a46f43
Showing with 100 additions and 142 deletions.
  1. +55 −119 examples/ansible.cfg
  2. +2 −0 lib/ansible/constants.py
  3. +3 −0 lib/ansible/errors.py
  4. +16 −9 lib/ansible/runner/__init__.py
  5. +24 −14 lib/ansible/utils/template.py
@@ -1,163 +1,99 @@
# config file for ansible -- http://ansible.github.com
#
# nearly all parameters can be overridden in ansible-playbook or with command line flags
# ansible will read ~/.ansible.cfg, ansible.cfg in the current working directory or
# config file for ansible -- http://ansibleworks.com/
# ==================================================

# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ~/.ansible.cfg,
# ansible.cfg in the current working directory or
# /etc/ansible/ansible.cfg, whichever it finds first

[defaults]

# location of inventory file, eliminates need to specify -i

hostfile = /etc/ansible/hosts

# location of ansible library, eliminates need to specify --module-path

library = /usr/share/ansible

# default module name used in /usr/bin/ansible when -m is not specified

module_name = command

# location for ansible log file. If set, will store output from ansible
# and ansible-playbook. If enabling, you may wish to configure
# logrotate.

#log_path = /var/log/ansible.log

# home directory where temp files are stored on remote systems. Should
# almost always contain $HOME or be a directory writeable by all users

remote_tmp = $HOME/.ansible/tmp

# the default pattern for ansible-playbooks ("hosts:")

pattern = *

# the default number of forks (parallelism) to be used. Usually you
# can crank this up.

forks=5

# the timeout used by various connection types. Usually this corresponds
# to an SSH timeout

timeout=10

# when using --poll or "poll:" in an ansible playbook, and not specifying
# an explicit poll interval, use this interval
# some basic default values...

poll_interval=15
hostfile = /etc/ansible/hosts
library = /usr/share/ansible
remote_tmp = $HOME/.ansible/tmp
pattern = *
forks = 5
poll_interval = 15
sudo_user = root
#ask_sudo_pass = True
#ask_pass = True
transport = paramiko
remote_port = 22

# when specifying --sudo to /usr/bin/ansible or "sudo:" in a playbook,
# and not specifying "--sudo-user" or "sudo_user" respectively, sudo
# to this user account
# change this for alternative sudo implementations
sudo_exe = sudo

sudo_user=root

# the following forces ansible to always ask for the sudo password (instead of having
# to add -K to the commandline). Or you can use the environment variable (ANSIBLE_ASK_SUDO_PASS)

#ask_sudo_pass=True

# the following forces ansible to always ask for the ssh-password (-k)
# can also be set by the environment variable ANSIBLE_ASK_PASS

#ask_pass=True

# connection to use when -c <connection_type> is not specified

transport=paramiko

# remote SSH port to be used when --port or "port:" or an equivalent inventory
# variable is not specified.

remote_port=22

# if set, always run /usr/bin/ansible commands as this user, and assume this value
# if "user:" is not set in a playbook. If not set, use the current Unix user
# as the default

#remote_user=root
# what flags to pass to sudo
# sudo_flags=-H

# the default sudo executable. If a sudo alternative with a sudo-compatible interface
# is used, specify its executable name as the default
# SSH timeout
timeout = 10

sudo_exe=sudo
# default user to use for playbooks if user is not specified
# (/usr/bin/ansible will use current user as default)
remote_user=root

# the default flags passed to sudo
# sudo_flags=-H
# logging is off by default unless this path is defined
# if so defined, consider logrotate
# log_path = /var/log/ansible.log

# all commands executed under sudo are passed as arguments to a shell command
# This shell command defaults to /bin/sh
# Changing this helps the situation where a user is only allowed to run
# e.g. /bin/bash with sudo privileges
# default module name for /usr/bin/ansible
module_name = command

# use this shell for commands executed under sudo
# you may need to change this to bin/bash in rare instances
# if sudo is constrained
# executable = /bin/sh

# how to handle hash defined in several places
# hash can be merged, or replaced
# if you use replace, and have multiple hashes named 'x', the last defined
# will override the previously defined one
# if you use merge here, hash will cumulate their keys, but keys will still
# override each other
# replace is the default value, and is how ansible always handled hash variables
#
# if inventory variables overlap, does the higher precedence one win
# or are hash values merged together? The default is 'replace' but
# this can also be set to 'merge'.
# hash_behaviour=replace

# How to handle variable replacement - as of 1.2, Jinja2 variable syntax is
# preferred, but we still support the old $variable replacement too.
# If you change legacy_playbook_variables to no then Ansible will no longer
# try to do replacement on $variable style variables.
#
# Turn off ${old_style} variables here if you like.
# legacy_playbook_variables=yes

# if you need to use jinja2 extensions, you can list them here
# use a coma to separate extensions, e.g. :
# list any Jinja2 extensions to enable here:
# jinja2_extensions=jinja2.ext.do,jinja2.ext.i18n
# no extensions are loaded by default

#jinja2_extensions=

# if set, always use this private key file for authentication, same as if passing
# --private-key to ansible or ansible-playbook

# if set, always use this private key file for authentication, same as
# if passing --private-key to ansible or ansible-playbook
#private_key_file=/path/to/file

# format of string $ansible_managed available within Jinja2 templates, replacing
# {file}, {host} and {uid} with template filename, host and owner respectively.
# The resulting string is passed through strftime(3) so it may contain any
# time-formatting specifiers.
#
# Example: ansible_managed = DONT TOUCH {file}: call {uid} at {host} for changes
# format of string {{ ansible_managed }} available within Jinja2
# templates indicates to users editing templates files will be replaced.
, replacing {file}, {host} and {uid} and strftime codes with proper values.
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}

# additional plugin paths for non-core plugins

# set plugin path directories here, seperate with colons
action_plugins = /usr/share/ansible_plugins/action_plugins
callback_plugins = /usr/share/ansible_plugins/callback_plugins
connection_plugins = /usr/share/ansible_plugins/connection_plugins
lookup_plugins = /usr/share/ansible_plugins/lookup_plugins
vars_plugins = /usr/share/ansible_plugins/vars_plugins
filter_plugins = /usr/share/ansible_plugins/filter_plugins

# set to 1 if you don't want cowsay support. Alternatively, set ANSIBLE_NOCOWS=1
# in your environment
# nocows = 1
# don't like cows? that's unfortunate.
# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1
# nocows = 1

[paramiko_connection]

# nothing to configure yet
# nothing configurable yet

[ssh_connection]

# if uncommented, sets the ansible ssh arguments to the following. Leaving off ControlPersist
# will result in poor performance, so use transport=paramiko on older platforms rather than
# removing it

# ssh arguments to use
# Leaving off ControlPersist will result in poor performance, so use
# paramiko on older platforms rather than removing it
ssh_args=-o ControlMaster=auto -o ControlPersist=60s -o ControlPath=/tmp/ansible-ssh-%h-%p-%r

# the following makes ansible use scp if the connection type is ssh (default is sftp)

# if True, make ansible use scp if the connection type is ssh
# (default is sftp)
#scp_if_ssh=True


@@ -110,6 +110,8 @@ def shell_expand_path(path):
ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', None)
ZEROMQ_PORT = int(get_config(p, 'fireball', 'zeromq_port', 'ANSIBLE_ZEROMQ_PORT', 5099))

DEFAULT_UNDEFINED_VAR_BEHAVIOR = get_config(p, DEFAULTS, 'error_on_undefined_vars', 'ANSIBLE_ERROR_ON_UNDEFINED_VARS', False)

# non-configurable things
DEFAULT_SUDO_PASS = None
DEFAULT_REMOTE_PASS = None
@@ -32,3 +32,6 @@ class AnsibleConnectionFailed(AnsibleError):

class AnsibleYAMLValidationFailed(AnsibleError):
pass

class AnsibleUndefinedVariable(AnsibleError):
pass
@@ -30,6 +30,7 @@
import sys
import shlex
import pipes
import jinja2

import ansible.constants as C
import ansible.inventory
@@ -128,7 +129,8 @@ def __init__(self,
check=False, # don't make any changes, just try to probe for potential changes
diff=False, # whether to show diffs for template files that change
environment=None, # environment variables (as dict) to use inside the command
complex_args=None # structured data in addition to module_args, must be a dict
complex_args=None, # structured data in addition to module_args, must be a dict
error_on_undefined_vars=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR # ex. False
):

if not complex_args:
@@ -164,6 +166,7 @@ def __init__(self,
self.environment = environment
self.complex_args = complex_args
self.module_with_list = False
self.error_on_undefined_vars = error_on_undefined_vars

self.callbacks.runner = self

@@ -446,11 +449,11 @@ def _executor_internal(self, host):
if type(complex_args) != dict:
raise errors.AnsibleError("args must be a dictionary, received %s" % complex_args)
result = self._executor_internal_inner(
host,
self.module_name,
self.module_args,
inject,
port,
host,
self.module_name,
self.module_args,
inject,
port,
complex_args=complex_args
)
results.append(result.result)
@@ -576,8 +579,12 @@ def _executor_internal_inner(self, host, module_name, module_args, inject, port,
tmp = self._make_tmp_path(conn)

# render module_args and complex_args templates
module_args = template.template(self.basedir, module_args, inject)
complex_args = template.template(self.basedir, complex_args, inject)
try:
module_args = template.template(self.basedir, module_args, inject, fail_on_undefined=self.error_on_undefined_vars)
complex_args = template.template(self.basedir, complex_args, inject, fail_on_undefined=self.error_on_undefined_vars)
except jinja2.exceptions.UndefinedError, e:
raise errors.AnsibleUndefinedVariable("Undefined variables: %s" % str(e))


result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)

@@ -644,7 +651,7 @@ def _remote_md5(self, conn, tmp, path):
path = pipes.quote(path)
# The following test needs to be SH-compliant. BASH-isms will
# not work if /bin/sh points to a non-BASH shell.
test = "rc=0; [ -r \"%s\" ] || rc=2; [ -f \"%s\" ] || rc=1; [ -d \"%s\" ] && rc=3" % ((path,) * 3)
test = "rc=0; [ -r \"%s\" ] || rc=2; [ -f \"%s\" ] || rc=1; [ -d \"%s\" ] && rc=3" % ((path,) * 3)
md5s = [
"(/usr/bin/md5sum %s 2>/dev/null)" % path, # Linux
"(/sbin/md5sum -q %s 2>/dev/null)" % path, # ?
Oops, something went wrong.

0 comments on commit 637983c

Please sign in to comment.