cchurch.scm
SCM
Checkout code from SCM (git/hg/svn).
Requirements
If checking out using SSH, a deployment key must be present for use by the
scm_target_user or SSH agent forwarding must be enabled for the Ansible SSH
connection.
sudo or similar privilege escalation is required to install the SCM package,
checkout as another user (i.e. scm_target_user != ansible_user), or create the
scm_target_user account.
Role Variables
Refer to the documentation for the git, hg or svn Ansible modules for more
specifics regarding parameters passed directly to the underlying modules.
The following variables are typically defined to use this role:
scm_type: One ofgit(default),hgorsvn.scm_url: URL to repository (e.g.http://server/repoorssh://server/repo), required.scm_version: Branch, tag, revision or commit to checkout (e.g.masterorHEAD).scm_force: Boolean indicating whether to passforceoption to SCM module, which will discard any modified files in an existing working directory; default isfalse.scm_delete_on_update: Boolean indicating whether to deletescm_target_pathbefore updating, default isfalse.scm_username: Username for accessingscm_url, only supported whenscm_typeissvn.scm_password: Password for accessingscm_url, only supported whenscm_typeissvn.scm_target_path: Target directory for checkout (default is"~/src").scm_target_user: User to become for checkout (default isansible_user, in which case no privilege escalation will be required). This user will be created if different fromansible_user, ignoring errors ifansible_useris unable to create the user.scm_target_user_home: Home directory to set if creatingscm_target_user.
The following variables may also be used to customize this role, though are not likely needed in most situations:
scm_accept_hostkey: Boolean indicating whether to accept SSH host key, only supported whenscm_typeisgit, role default istrue.scm_depth: Create a shallow clone, minimum value is1; only supported whenscm_typeisgit; role default is unspecified.scm_executable: Path togit,hgorsvnbinary; default is unspecified, which searches system binary paths.scm_export: Export instead of checkout/update; only supported whenscm_typeissvn; role default is unspecified, but thesvnmodule default isfalse.scm_key_file: Path to private key file on the target to use for checkout; default is unspecified; only supported whenscm_typeisgit.scm_purge: Delete untracked files when updating; only supported whenscm_typeishg; role default is unspecified, but thehgmodule default isfalse.scm_recursive: Boolean indicating whether to clone respotitory recursively, including submodules; only supported whenscm_typeisgit; role default is unspecified, but thegitmodule default istrue.scm_remote: Name of the remote; only supported whenscm_typeisgit; role default is unspecified, but thegitmodule default is"origin".scm_switch: Callsvn switchbefore update; only supported whenscm_typeissvn; role default is unspecified, but thesvnmodule default istrue.scm_track_submodules: Boolean indicating whether submodules track the latest commits; only supported whenscm_typeisgit; role default is unspecified, but thegitmodule default isfalse.scm_update: Boolean indicating whether to receive new revisions from the origin repository; role default is unspecified, but modules default totrue.scm_verify_commit: Boolean indicating whether to validate GPG signed commits; only supported whenscm_typeisgit; role default is unspecified but thegitmodule default isfalse.scm_packages: Mapping of packages byansible_pkg_mgrandscm_type. The role will attempt to install the required package, ignoring errors if the appropriate privilege escalation is not available. There is normally no need to change this variable unless running on a system using a differentansible_pkg_mgrthanyum,apt,pacmanormacports.scm_ssh_agent_forwarding: Boolean indicating whether to apply fixes to allow SSH agent fowarding to work whenscm_target_useris not the same asansible_user; role default isfalse.scm_ssh_auth_sock_sudoers_file: File path to be added insudoers.dwhenscm_ssh_agent_forwardingfix is enabled; role default is"/etc/sudoers.d/ssh_auth_sock".
The following variable may be defined for the play or role invocation (but will not work if defined as an inventory group or host variable):
scm_notify_on_updated: Handler name to notify when the checkout was changed. The default is"scm updated"; it is generally recommended for custom handlers to listen for"scm updated"instead of changing the notification name.
The role will also set the scm_update_result fact (per host) to the result of
the update task.
Dependencies
None.
Example Playbook
The following example playbook checks out a public git repo and displays a message after updating:
- hosts: all
roles:
- role: cchurch.scm
vars:
scm_type: git
scm_url: https://github.com/cchurch/ansible-sign.git
scm_target_path: ~/src/ansible-sign
scm_version: master
handlers:
- name: ansible sign updated
debug:
msg: "{{ scm_target_path }} was updated from {{ scm_url }} to {{ scm_update_result.after }}."
listen: scm updated
License
BSD
Author Information
Chris Church (cchurch)
ansible-galaxy install cchurch.scm