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),hg
orsvn
.scm_url
: URL to repository (e.g.http://server/repo
orssh://server/repo
), required.scm_version
: Branch, tag, revision or commit to checkout (e.g.master
orHEAD
).scm_force
: Boolean indicating whether to passforce
option 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_path
before updating, default isfalse
.scm_username
: Username for accessingscm_url
, only supported whenscm_type
issvn
.scm_password
: Password for accessingscm_url
, only supported whenscm_type
issvn
.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_user
is 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_type
isgit
, role default istrue
.scm_depth
: Create a shallow clone, minimum value is1
; only supported whenscm_type
isgit
; role default is unspecified.scm_executable
: Path togit
,hg
orsvn
binary; default is unspecified, which searches system binary paths.scm_export
: Export instead of checkout/update; only supported whenscm_type
issvn
; role default is unspecified, but thesvn
module default isfalse
.scm_key_file
: Path to private key file on the target to use for checkout; default is unspecified; only supported whenscm_type
isgit
.scm_purge
: Delete untracked files when updating; only supported whenscm_type
ishg
; role default is unspecified, but thehg
module default isfalse
.scm_recursive
: Boolean indicating whether to clone respotitory recursively, including submodules; only supported whenscm_type
isgit
; role default is unspecified, but thegit
module default istrue
.scm_remote
: Name of the remote; only supported whenscm_type
isgit
; role default is unspecified, but thegit
module default is"origin"
.scm_switch
: Callsvn switch
before update; only supported whenscm_type
issvn
; role default is unspecified, but thesvn
module default istrue
.scm_track_submodules
: Boolean indicating whether submodules track the latest commits; only supported whenscm_type
isgit
; role default is unspecified, but thegit
module 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_type
isgit
; role default is unspecified but thegit
module default isfalse
.scm_packages
: Mapping of packages byansible_pkg_mgr
andscm_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_mgr
thanyum
,apt
,pacman
ormacports
.scm_ssh_agent_forwarding
: Boolean indicating whether to apply fixes to allow SSH agent fowarding to work whenscm_target_user
is not the same asansible_user
; role default isfalse
.scm_ssh_auth_sock_sudoers_file
: File path to be added insudoers.d
whenscm_ssh_agent_forwarding
fix 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/ansible-role-scm