Remove extra_vars tests

This commit is contained in:
Michael DeHaan 2012-04-16 23:03:04 -04:00
parent b24ec71ca3
commit 9ce27be878
6 changed files with 13 additions and 60 deletions

View file

@ -77,11 +77,6 @@ Connection timeout to use when trying to talk to hosts, in
\fISECONDS\fR\&.
.RE
.PP
\fB\-e\fR \fIEXTRA_VARS\fR, \fB\-\-extra_vars=\fR\fIEXTRA_VARS\fR
.RS 4
An additional list of space delimited key=value pairs to pass into the playbook that are not declared in the vars section of the playbook\&.
.RE
.PP
\fB\-O\fR \fIOVERRIDE_HOSTS\fR, \fB\-\-override\-hosts=\fR\fIOVERRIDE_HOSTS\fR
.RS 4
Ignore the inventory file and run the playbook against only these hosts\&. "hosts:" line in playbook should be set to

View file

@ -69,12 +69,6 @@ Prompt for the password to use for playbook plays that request sudo access, if a
Connection timeout to use when trying to talk to hosts, in 'SECONDS'.
*-e* 'EXTRA_VARS', *--extra_vars=*'EXTRA_VARS'::
An additional list of space delimited key=value pairs to pass into the playbook that are not
declared in the vars section of the playbook.
*-O* 'OVERRIDE_HOSTS', *--override-hosts=*'OVERRIDE_HOSTS'::
Ignore the inventory file and run the playbook against only these hosts. "hosts:" line

View file

@ -32,7 +32,7 @@ class Inventory(object):
systems, or a script that will be called with --list or --host.
"""
def __init__(self, host_list=C.DEFAULT_HOST_LIST, extra_vars=None):
def __init__(self, host_list=C.DEFAULT_HOST_LIST):
self._restriction = None
self._variables = {}
@ -50,7 +50,7 @@ class Inventory(object):
self.inventory_file = os.path.abspath(inventory_file)
if os.access(self.inventory_file, os.X_OK):
self.host_list, self.groups = self._parse_from_script(extra_vars)
self.host_list, self.groups = self._parse_from_script()
self._is_script = True
else:
self.host_list, self.groups = self._parse_from_file()
@ -78,7 +78,7 @@ class Inventory(object):
""" Do not restrict list operations """
self._restriction = None
def get_variables(self, host, extra_vars=None):
def get_variables(self, host):
""" Return the variables associated with this host. """
if host in self._variables:
@ -87,7 +87,7 @@ class Inventory(object):
if not self._is_script:
return {}
return self._get_variables_from_script(host, extra_vars)
return self._get_variables_from_script(host)
# *****************************************************
@ -126,7 +126,7 @@ class Inventory(object):
# *****************************************************
def _parse_from_script(self, extra_vars=None):
def _parse_from_script(self):
''' evaluate a script that returns list of hosts by groups '''
results = []
@ -134,9 +134,6 @@ class Inventory(object):
cmd = [self.inventory_file, '--list']
if extra_vars:
cmd.extend(['--extra-vars', extra_vars])
cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
out, err = cmd.communicate()
rc = cmd.returncode
@ -241,14 +238,11 @@ class Inventory(object):
raise AnsibleError("Unknown item in inventory: %s"%(item))
def _get_variables_from_script(self, host, extra_vars=None):
def _get_variables_from_script(self, host):
''' support per system variabes from external variable scripts, see web docs '''
cmd = [self.inventory_file, '--host', host]
if extra_vars:
cmd.extend(['--extra-vars', extra_vars])
cmd = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,

View file

@ -59,7 +59,6 @@ class PlayBook(object):
remote_port = C.DEFAULT_REMOTE_PORT,
transport = C.DEFAULT_TRANSPORT,
override_hosts = None,
extra_vars = None,
debug = False,
verbose = False,
callbacks = None,
@ -82,7 +81,6 @@ class PlayBook(object):
self.callbacks = callbacks
self.runner_callbacks = runner_callbacks
self.override_hosts = override_hosts
self.extra_vars = extra_vars
self.stats = stats
self.sudo = sudo
self.sudo_pass = sudo_pass
@ -323,7 +321,7 @@ class PlayBook(object):
remote_port=port, module_vars=vars,
setup_cache=SETUP_CACHE, basedir=self.basedir,
conditional=only_if, callbacks=self.runner_callbacks,
extra_vars=self.extra_vars, debug=self.debug, sudo=sudo,
debug=self.debug, sudo=sudo,
transport=transport, sudo_pass=self.sudo_pass, is_playbook=True
)
@ -505,14 +503,6 @@ class PlayBook(object):
for (host, result) in setup_ok.iteritems():
SETUP_CACHE[host] = result
if self.extra_vars:
extra_vars = utils.parse_kv(self.extra_vars)
for h in self.host_list:
try:
SETUP_CACHE[h].update(extra_vars)
except:
SETUP_CACHE[h] = extra_vars
# *****************************************************
def _run_play(self, pg):

View file

@ -90,7 +90,6 @@ class Runner(object):
verbose=False,
debug=False,
sudo=False,
extra_vars=None,
module_vars=None,
is_playbook=False,
inventory=None):
@ -109,7 +108,7 @@ class Runner(object):
self.connector = ansible.connection.Connection(self, self.transport)
if inventory is None:
self.inventory = ansible.inventory.Inventory(host_list, extra_vars)
self.inventory = ansible.inventory.Inventory(host_list)
else:
self.inventory = inventory
@ -121,7 +120,6 @@ class Runner(object):
self.pattern = pattern
self.module_args = module_args
self.module_vars = module_vars
self.extra_vars = extra_vars
self.timeout = timeout
self.debug = debug
self.verbose = verbose
@ -146,13 +144,13 @@ class Runner(object):
# *****************************************************
@classmethod
def parse_hosts(cls, host_list, override_hosts=None, extra_vars=None):
def parse_hosts(cls, host_list, override_hosts=None):
''' parse the host inventory file, returns (hosts, groups) '''
if override_hosts is None:
inventory = ansible.inventory.Inventory(host_list, extra_vars)
inventory = ansible.inventory.Inventory(host_list)
else:
inventory = ansible.inventory.Inventory(override_hosts, extra_vars)
inventory = ansible.inventory.Inventory(override_hosts)
return inventory.host_list, inventory.groups
@ -267,7 +265,7 @@ class Runner(object):
if not eval(conditional):
return [ utils.smjson(dict(skipped=True)), None, 'skipped' ]
host_variables = self.inventory.get_variables(conn.host, self.extra_vars)
host_variables = self.inventory.get_variables(conn.host)
inject.update(host_variables)
if self.module_name == 'setup':
@ -517,7 +515,7 @@ class Runner(object):
def _executor_internal(self, host):
''' callback executed in parallel for each host. returns (hostname, connected_ok, extra) '''
host_variables = self.inventory.get_variables(host, self.extra_vars)
host_variables = self.inventory.get_variables(host)
port = host_variables.get('ansible_ssh_port', self.remote_port)
conn = None

View file

@ -87,12 +87,6 @@ class TestInventory(unittest.TestCase):
assert vars == {}
def test_simple_extra_vars(self):
inventory = self.simple_inventory()
vars = inventory.get_variables('thor', 'a=5')
assert vars == {}
def test_simple_port(self):
inventory = self.simple_inventory()
vars = inventory.get_variables('hera')
@ -154,12 +148,6 @@ class TestInventory(unittest.TestCase):
assert vars == {"hammer":True}
def test_script_extra_vars(self):
inventory = self.script_inventory()
vars = inventory.get_variables('thor', 'simple=yes')
assert vars == {"hammer":True, "simple": "yes"}
### Tests for yaml inventory file
def test_yaml(self):
@ -234,12 +222,6 @@ class TestInventory(unittest.TestCase):
assert vars == {"moon":"titan"}
def test_yaml_extra_vars(self):
inventory = self.yaml_inventory()
vars = inventory.get_variables('thor', 'a=5')
assert vars == {"hammer":True}
def test_yaml_port(self):
inventory = self.yaml_inventory()
vars = inventory.get_variables('hera')