Documentation

maven_artifact - Downloads an Artifact from a Maven Repository

New in version 2.0.

Synopsis

  • Downloads an artifact from a maven repository given the maven coordinates provided to the module.
  • Can retrieve snapshots or release versions of the artifact and will resolve the latest available version if one is not available.

Requirements (on host that executes module)

  • python >= 2.6
  • lxml
  • boto if using a S3 repository (s3://...)

Options

parameter required default choices comments
artifact_id
yes
The maven artifactId coordinate
attributes
(added in 2.3)
no None
Attributes the file or directory should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr.

aliases: attr
classifier
no
The maven classifier coordinate
dest
yes
The path where the artifact should be written to
If file mode or ownerships are specified and destination path already exists, they affect the downloaded file
extension
no jar
The maven type/extension coordinate
group
no
Name of the group that should own the file/directory, as would be fed to chown.
group_id
yes
The Maven groupId coordinate
keep_name
(added in 2.4)
no no
  • yes
  • no
If yes, the downloaded artifact's name is preserved, i.e the version number remains part of it.
This option only has effect when dest is a directory and version is set to latest.
mode
no
Mode the file or directory should be. For those used to /usr/bin/chmod remember that modes are actually octal numbers (like 0644). Leaving off the leading zero will likely have unexpected results. As of version 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r).
owner
no
Name of the user that should own the file/directory, as would be fed to chown.
password
no
The password to authenticate with to the Maven Repository. Use AWS secret access key of the repository is hosted on S3

aliases: aws_secret_access_key
repository_url
no http://repo1.maven.org/maven2
The URL of the Maven Repository to download from.
Use s3://... if the repository is hosted on Amazon S3, added in version 2.2.
selevel
no s0
Level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the range. _default feature works as for seuser.
serole
no
Role part of SELinux file context, _default feature works as for seuser.
setype
no
Type part of SELinux file context, _default feature works as for seuser.
seuser
no
User part of SELinux file context. Will default to system policy, if applicable. If set to _default, it will use the user portion of the policy if available.
state
yes present
  • present
  • absent
The desired state of the artifact
timeout
(added in 2.3)
no 10
Specifies a timeout in seconds for the connection attempt
unsafe_writes
(added in 2.2)
no
  • yes
  • no
Normally this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, sometimes systems are configured or just broken in ways that prevent this. One example are docker mounted files, they cannot be updated atomically and can only be done in an unsafe manner.
This boolean option allows ansible to fall back to unsafe methods of updating files for those cases in which you do not have any other choice. Be aware that this is subject to race conditions and can lead to data corruption.
username
no
The username to authenticate as to the Maven Repository. Use AWS secret key of the repository is hosted on S3

aliases: aws_secret_key
validate_certs
(added in 1.9.3)
no yes
  • yes
  • no
If no, SSL certificates will not be validated. This should only be set to no when no other option exists.
version
no latest
The maven version coordinate

Examples

# Download the latest version of the JUnit framework artifact from Maven Central
- maven_artifact:
    group_id: junit
    artifact_id: junit
    dest: /tmp/junit-latest.jar

# Download JUnit 4.11 from Maven Central
- maven_artifact:
    group_id: junit
    artifact_id: junit
    version: 4.11
    dest: /tmp/junit-4.11.jar

# Download an artifact from a private repository requiring authentication
- maven_artifact:
    group_id: com.company
    artifact_id: library-name
    repository_url: 'https://repo.company.com/maven'
    username: user
    password: pass
    dest: /tmp/library-name-latest.jar

# Download a WAR File to the Tomcat webapps directory to be deployed
- maven_artifact:
    group_id: com.company
    artifact_id: web-app
    extension: war
    repository_url: 'https://repo.company.com/maven'
    dest: /var/lib/tomcat7/webapps/web-app.war

# Keep a downloaded artifact's name, i.e. retain the version
- maven_artifact:
    version: latest
    artifact_id: spring-core
    group_id: org.springframework
    dest: /tmp/
    keep_name: yes

Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.