mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-15 17:40:50 -07:00
Introduce a connection locking infrastructure
The lock file is (a temporary file) opened in the parent process, whose open fd is inherited by the workers after fork, and passed down through the PlayContext. Connection grows lock/unlock methods which can be used by individual connection plugins.
This commit is contained in:
parent
88d3751c28
commit
5887e96b27
3 changed files with 21 additions and 0 deletions
|
@ -155,3 +155,13 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
|
|||
if incorrect_password in output:
|
||||
raise AnsibleError('Incorrect %s password' % self._play_context.become_method)
|
||||
|
||||
def lock_connection(self):
|
||||
f = self._play_context.connection_lockfd
|
||||
self._display.vvvv('CONNECTION: pid %d waiting for lock on %d' % (os.getpid(), f))
|
||||
fcntl.lockf(f, fcntl.LOCK_EX)
|
||||
self._display.vvvv('CONNECTION: pid %d acquired lock on %d' % (os.getpid(), f))
|
||||
|
||||
def unlock_connection(self):
|
||||
f = self._play_context.connection_lockfd
|
||||
fcntl.lockf(f, fcntl.LOCK_UN)
|
||||
self._display.vvvv('CONNECTION: pid %d released lock on %d' % (os.getpid(), f))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue