|
|
@ -1,24 +1,21 @@
|
|
|
|
#!/usr/bin/python
|
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
# (c) 2013, Yeukhon Wong <yeukhon@acm.org>
|
|
|
|
# Copyright: (c) 2013, Yeukhon Wong <yeukhon@acm.org>
|
|
|
|
# (c) 2014, Nate Coraor <nate@bx.psu.edu>
|
|
|
|
# Copyright: (c) 2014, Nate Coraor <nate@bx.psu.edu>
|
|
|
|
#
|
|
|
|
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|
|
|
'status': ['preview'],
|
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
---
|
|
|
|
module: hg
|
|
|
|
module: hg
|
|
|
|
short_description: Manages Mercurial (hg) repositories.
|
|
|
|
short_description: Manages Mercurial (hg) repositories
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Manages Mercurial (hg) repositories. Supports SSH, HTTP/S and local address.
|
|
|
|
- Manages Mercurial (hg) repositories. Supports SSH, HTTP/S and local address.
|
|
|
|
version_added: "1.0"
|
|
|
|
version_added: "1.0"
|
|
|
@ -27,76 +24,64 @@ options:
|
|
|
|
repo:
|
|
|
|
repo:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The repository address.
|
|
|
|
- The repository address.
|
|
|
|
required: true
|
|
|
|
required: yes
|
|
|
|
default: null
|
|
|
|
|
|
|
|
aliases: [ name ]
|
|
|
|
aliases: [ name ]
|
|
|
|
dest:
|
|
|
|
dest:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Absolute path of where the repository should be cloned to.
|
|
|
|
- Absolute path of where the repository should be cloned to.
|
|
|
|
This parameter is required, unless clone and update are set to no
|
|
|
|
This parameter is required, unless clone and update are set to no
|
|
|
|
required: true
|
|
|
|
required: yes
|
|
|
|
default: null
|
|
|
|
|
|
|
|
revision:
|
|
|
|
revision:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Equivalent C(-r) option in hg command which could be the changeset, revision number,
|
|
|
|
- Equivalent C(-r) option in hg command which could be the changeset, revision number,
|
|
|
|
branch name or even tag.
|
|
|
|
branch name or even tag.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
aliases: [ version ]
|
|
|
|
aliases: [ version ]
|
|
|
|
force:
|
|
|
|
force:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Discards uncommitted changes. Runs C(hg update -C). Prior to
|
|
|
|
- Discards uncommitted changes. Runs C(hg update -C). Prior to
|
|
|
|
1.9, the default was `yes`.
|
|
|
|
1.9, the default was `yes`.
|
|
|
|
required: false
|
|
|
|
type: bool
|
|
|
|
default: "no"
|
|
|
|
default: 'no'
|
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
|
|
|
|
purge:
|
|
|
|
purge:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Deletes untracked files. Runs C(hg purge).
|
|
|
|
- Deletes untracked files. Runs C(hg purge).
|
|
|
|
required: false
|
|
|
|
type: bool
|
|
|
|
default: "no"
|
|
|
|
default: 'no'
|
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
|
|
|
|
update:
|
|
|
|
update:
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: "yes"
|
|
|
|
|
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
|
|
|
|
version_added: "2.0"
|
|
|
|
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- If C(no), do not retrieve new revisions from the origin repository
|
|
|
|
- If C(no), do not retrieve new revisions from the origin repository
|
|
|
|
|
|
|
|
type: bool
|
|
|
|
|
|
|
|
default: 'yes'
|
|
|
|
|
|
|
|
version_added: '2.0'
|
|
|
|
clone:
|
|
|
|
clone:
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: "yes"
|
|
|
|
|
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
|
|
|
|
version_added: "2.3"
|
|
|
|
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- If C(no), do not clone the repository if it does not exist locally.
|
|
|
|
- If C(no), do not clone the repository if it does not exist locally.
|
|
|
|
|
|
|
|
type: bool
|
|
|
|
|
|
|
|
default: 'yes'
|
|
|
|
|
|
|
|
version_added: '2.3'
|
|
|
|
executable:
|
|
|
|
executable:
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
version_added: "1.4"
|
|
|
|
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Path to hg executable to use. If not supplied,
|
|
|
|
- Path to hg executable to use. If not supplied,
|
|
|
|
the normal mechanism for resolving binary paths will be used.
|
|
|
|
the normal mechanism for resolving binary paths will be used.
|
|
|
|
|
|
|
|
version_added: '1.4'
|
|
|
|
notes:
|
|
|
|
notes:
|
|
|
|
- "This module does not support push capability. See U(https://github.com/ansible/ansible/issues/31156)."
|
|
|
|
- This module does not support push capability. See U(https://github.com/ansible/ansible/issues/31156).
|
|
|
|
- "If the task seems to be hanging, first verify remote host is in C(known_hosts).
|
|
|
|
- "If the task seems to be hanging, first verify remote host is in C(known_hosts).
|
|
|
|
SSH will prompt user to authorize the first contact with a remote host. To avoid this prompt,
|
|
|
|
SSH will prompt user to authorize the first contact with a remote host. To avoid this prompt,
|
|
|
|
one solution is to add the remote host public key in C(/etc/ssh/ssh_known_hosts) before calling
|
|
|
|
one solution is to add the remote host public key in C(/etc/ssh/ssh_known_hosts) before calling
|
|
|
|
the hg module, with the following command: ssh-keyscan remote_host.com >> /etc/ssh/ssh_known_hosts."
|
|
|
|
the hg module, with the following command: ssh-keyscan remote_host.com >> /etc/ssh/ssh_known_hosts."
|
|
|
|
requirements: [ ]
|
|
|
|
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
EXAMPLES = '''
|
|
|
|
# Ensure the current working copy is inside the stable branch and deletes untracked files if any.
|
|
|
|
- name: Ensure the current working copy is inside the stable branch and deletes untracked files if any.
|
|
|
|
- hg:
|
|
|
|
hg:
|
|
|
|
repo: https://bitbucket.org/user/repo1
|
|
|
|
repo: https://bitbucket.org/user/repo1
|
|
|
|
dest: /home/user/repo1
|
|
|
|
dest: /home/user/repo1
|
|
|
|
revision: stable
|
|
|
|
revision: stable
|
|
|
|
purge: yes
|
|
|
|
purge: yes
|
|
|
|
|
|
|
|
|
|
|
|
# Example just get information about the repository whether or not it has
|
|
|
|
- name: Get information about the repository whether or not it has already been cloned locally.
|
|
|
|
# already been cloned locally.
|
|
|
|
hg:
|
|
|
|
- hg:
|
|
|
|
|
|
|
|
repo: git://bitbucket.org/user/repo
|
|
|
|
repo: git://bitbucket.org/user/repo
|
|
|
|
dest: /srv/checkout
|
|
|
|
dest: /srv/checkout
|
|
|
|
clone: no
|
|
|
|
clone: no
|
|
|
@ -110,7 +95,6 @@ from ansible.module_utils._text import to_native
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Hg(object):
|
|
|
|
class Hg(object):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, module, dest, repo, revision, hg_path):
|
|
|
|
def __init__(self, module, dest, repo, revision, hg_path):
|
|
|
|
self.module = module
|
|
|
|
self.module = module
|
|
|
|
self.dest = dest
|
|
|
|
self.dest = dest
|
|
|
@ -229,19 +213,20 @@ class Hg(object):
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ===========================================
|
|
|
|
# ===========================================
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
argument_spec=dict(
|
|
|
|
repo = dict(required=True, aliases=['name']),
|
|
|
|
repo=dict(type='str', required=True, aliases=['name']),
|
|
|
|
dest=dict(type='path'),
|
|
|
|
dest=dict(type='path'),
|
|
|
|
revision = dict(default=None, aliases=['version']),
|
|
|
|
revision=dict(type='str', default=None, aliases=['version']),
|
|
|
|
force = dict(default='no', type='bool'),
|
|
|
|
force=dict(type='bool', default=False),
|
|
|
|
purge = dict(default='no', type='bool'),
|
|
|
|
purge=dict(type='bool', default=False),
|
|
|
|
update = dict(default='yes', type='bool'),
|
|
|
|
update=dict(type='bool', default=True),
|
|
|
|
clone = dict(default='yes', type='bool'),
|
|
|
|
clone=dict(type='bool', default=True),
|
|
|
|
executable = dict(default=None),
|
|
|
|
executable=dict(type='str', default=None),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
repo = module.params['repo']
|
|
|
|
repo = module.params['repo']
|
|
|
@ -304,7 +289,9 @@ def main():
|
|
|
|
after = hg.get_revision()
|
|
|
|
after = hg.get_revision()
|
|
|
|
if before != after or cleaned:
|
|
|
|
if before != after or cleaned:
|
|
|
|
changed = True
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
|
|
|
|
module.exit_json(before=before, after=after, changed=changed, cleaned=cleaned)
|
|
|
|
module.exit_json(before=before, after=after, changed=changed, cleaned=cleaned)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
main()
|
|
|
|