the return of reset_connection

allows user to force persistent connection to close, needed for when
you want to benefit from changes applied to the current play but persistent connections
prevent them from being realized.
pull/20872/head
Brian Coca 8 years ago committed by Brian Coca
parent 36aad569d2
commit cc0bb54d2c

@ -40,6 +40,7 @@ options:
- "C(clear_facts) (added in 2.1) causes the gathered facts for the hosts specified in the play's list of hosts to be cleared, including the fact cache." - "C(clear_facts) (added in 2.1) causes the gathered facts for the hosts specified in the play's list of hosts to be cleared, including the fact cache."
- "C(clear_host_errors) (added in 2.1) clears the failed state (if any) from hosts specified in the play's list of hosts." - "C(clear_host_errors) (added in 2.1) clears the failed state (if any) from hosts specified in the play's list of hosts."
- "C(end_play) (added in 2.2) causes the play to end without failing the host." - "C(end_play) (added in 2.2) causes the play to end without failing the host."
- "C(reset_connection) (added in 2.3) interrupts a persistent connection (i.e. ssh + control persist)"
choices: ['noop', 'flush_handlers', 'refresh_inventory', 'clear_facts', 'clear_host_errors', 'end_play'] choices: ['noop', 'flush_handlers', 'refresh_inventory', 'clear_facts', 'clear_host_errors', 'end_play']
required: true required: true
default: null default: null
@ -50,29 +51,32 @@ author:
''' '''
EXAMPLES = ''' EXAMPLES = '''
# force all notified handlers to run at this point, not waiting for normal sync points
- template: - template:
src: new.j2 src: new.j2
dest: /etc/config.txt dest: /etc/config.txt
notify: myhandler notify: myhandler
- meta: flush_handlers - name: force all notified handlers to run at this point, not waiting for normal sync points
meta: flush_handlers
# reload inventory, useful with dynamic inventories when play makes changes to the existing hosts - name: reload inventory, useful with dynamic inventories when play makes changes to the existing hosts
- cloud_guest: # this is fake module cloud_guest: # this is fake module
name: newhost name: newhost
state: present state: present
- name: Refresh inventory to ensure new instaces exist in inventory - name: Refresh inventory to ensure new instaces exist in inventory
meta: refresh_inventory meta: refresh_inventory
- name: Clear gathered facts from all currently targeted hosts - name: Clear gathered facts from all currently targeted hosts
meta: clear_facts meta: clear_facts
# bring host back to play after failure - name: bring host back to play after failure
- copy: copy:
src: file src: file
dest: /etc/file dest: /etc/file
remote_user: imightnothavepermission remote_user: imightnothavepermission
- meta: clear_host_errors - meta: clear_host_errors
- user: name={{ansible_user}} groups=input
- name: reset ssh connection to allow user changes to affect 'current login user'
meta: reset_connection
''' '''

@ -776,18 +776,16 @@ class Connection(ConnectionBase):
display.vvv(u"FETCH {0} TO {1}".format(in_path, out_path), host=self.host) display.vvv(u"FETCH {0} TO {1}".format(in_path, out_path), host=self.host)
self._file_transport_command(in_path, out_path, 'get') self._file_transport_command(in_path, out_path, 'get')
def close(self): def reset(self):
# If we have a persistent ssh connection (ControlPersist), we can ask it # If we have a persistent ssh connection (ControlPersist), we can ask it to stop listening.
# to stop listening. Otherwise, there's nothing to do here. cmd = map(to_bytes, self._build_command(self._play_context.ssh_executable, '-O', 'stop', self.host))
controlpersist, controlpath = self._persistence_controls(cmd)
# TODO: reenable once winrm issues are fixed if controlpersist:
# temporarily disabled as we are forced to currently close connections after every task because of winrm p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# if self._connected and self._persistent: stdout, stderr = p.communicate()
# ssh_executable = self._play_context.ssh_executable display.vvv(u'sending stop: %s' % cmd)
# cmd = self._build_command('ssh', '-O', 'stop', self.host)
# self.close()
# cmd = map(to_bytes, cmd)
# p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# stdout, stderr = p.communicate()
def close(self):
self._connected = False self._connected = False

@ -902,8 +902,10 @@ class StrategyBase:
if not host.name in self._tqm._unreachable_hosts: if not host.name in self._tqm._unreachable_hosts:
iterator._host_states[host.name].run_state = iterator.ITERATING_COMPLETE iterator._host_states[host.name].run_state = iterator.ITERATING_COMPLETE
msg="ending play" msg="ending play"
#elif meta_action == 'reset_connection': elif meta_action == 'reset_connection':
# connection_info.connection.close() connection = connection_loader.get(play_context.connection, play_context, '/dev/null')
connection.reset()
msg= 'reset connection'
else: else:
raise AnsibleError("invalid meta action requested: %s" % meta_action, obj=task._ds) raise AnsibleError("invalid meta action requested: %s" % meta_action, obj=task._ds)

Loading…
Cancel
Save