From cf3edf09897aec4338a278c4bf291e9aef25da63 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 23 Feb 2017 15:37:29 -0500 Subject: [PATCH] more examples and clearer override docs for conn fixes #21866 --- docs/docsite/rst/playbooks_variables.rst | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/docsite/rst/playbooks_variables.rst b/docs/docsite/rst/playbooks_variables.rst index 47cc23ee7c..b18222b4b6 100644 --- a/docs/docsite/rst/playbooks_variables.rst +++ b/docs/docsite/rst/playbooks_variables.rst @@ -859,15 +859,30 @@ Basically, anything that goes into "role defaults" (the defaults folder inside t .. note:: the previous describes the default config `hash_behavior=replace`, switch to 'merge' to only partially overwrite. -Another important thing to consider (for all versions) is that connection specific variables override config, command line and play specific options and directives. For example:: +Another important thing to consider (for all versions) is that connection variables override config, command line and play/role/task specific options and directives. For example:: - ansible_ssh_user will override `-u ` and `remote_user: ` + ansible -u lola myhost + +This will still connect as ``ramon`` as ``ansible_ssh_user`` is set to ``ramon`` in inventory for myhost. +For plays/tasks this is also true for ``remote_user``:: + + - hosts: myhost + tasks: + - command: i'll connect as ramon still + remote_user: lola This is done so host specific settings can override the general settings. These variables are normally defined per host or group in inventory, but they behave like other variables, so if you really want to override the remote user globally even over inventory you can use extra vars:: - ansible... -e "ansible_ssh_user=" + ansible... -e "ansible_user=" +You can also override as a normal variable in a play:: + + - hosts: all + vars: + ansible_user: lola + tasks: + - command: i'll connect as lola! .. _variable_scopes: