community.general.maven_artifact – Downloads an Artifact from a Maven Repository

Note

This plugin is part of the community.general collection (version 1.3.6).

To install it use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.maven_artifact.

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

The below requirements are needed on the host that executes this module.

  • lxml

  • boto if using a S3 repository (s3://…)

Parameters

Parameter Choices/Defaults Comments
artifact_id
string / required
The maven artifactId coordinate
attributes
string
added in 2.3 of ansible.builtin
The attributes the resulting 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.
The = operator is assumed as default, otherwise + or - operators need to be included in the string.

aliases: attr
classifier
string
The maven classifier coordinate
client_cert
path
added in 1.3.0 of community.general
PEM formatted certificate chain file to be used for SSL client authentication.
This file can also include the key as well, and if the key is included, client_key is not required.
client_key
path
added in 1.3.0 of community.general
PEM formatted file that contains your private key to be used for SSL client authentication.
If client_cert contains both the certificate and key, this option is not required.
dest
path / required
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
string
Default:
"jar"
The maven type/extension coordinate
force_basic_auth
boolean
added in 0.2.0 of community.general
    Choices:
  • no ←
  • yes
httplib2, the library used by the uri module only sends authentication information when a webservice responds to an initial request with a 401 status. Since some basic auth services do not properly send a 401, logins will fail. This option forces the sending of the Basic authentication header upon initial request.
group
string
Name of the group that should own the file/directory, as would be fed to chown.
group_id
string / required
The Maven groupId coordinate
headers
dictionary
Add custom HTTP headers to a request in hash/dict format.
keep_name
boolean
    Choices:
  • no ←
  • yes
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 or version_by_spec is defined.
mode
raw
The permissions the resulting file or directory should have.
For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like 0644 or 01777) or quote it (like '644' or '1777') so Ansible receives a string and can do its own conversion from string into number.
Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results.
As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r).
owner
string
Name of the user that should own the file/directory, as would be fed to chown.
password
string
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
string
Default:
"https://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.
Use file://... if the repository is local, added in version 2.6
selevel
string
The level part of the SELinux file context.
This is the MLS/MCS attribute, sometimes known as the range.
When set to _default, it will use the level portion of the policy if available.
serole
string
The role part of the SELinux file context.
When set to _default, it will use the role portion of the policy if available.
setype
string
The type part of the SELinux file context.
When set to _default, it will use the type portion of the policy if available.
seuser
string
The user part of the SELinux file context.
By default it uses the system policy, where applicable.
When set to _default, it will use the user portion of the policy if available.
state
string
    Choices:
  • present ←
  • absent
The desired state of the artifact
timeout
integer
Default:
10
Specifies a timeout in seconds for the connection attempt
unsafe_writes
boolean
added in 2.2 of ansible.builtin
    Choices:
  • no ←
  • yes
Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target file.
By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted files, which cannot be updated atomically from inside the container and can only be written in an unsafe manner.
This option allows Ansible to fall back to unsafe methods of updating files when atomic operations fail (however, it doesn't force Ansible to perform unsafe writes).
IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption.
username
string
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
boolean
    Choices:
  • no
  • yes ←
If no, SSL certificates will not be validated. This should only be set to no when no other option exists.
verify_checksum
string
    Choices:
  • never
  • download ←
  • change
  • always
If never, the md5 checksum will never be downloaded and verified.
If download, the md5 checksum will be downloaded and verified only after artifact download. This is the default.
If change, the md5 checksum will be downloaded and verified if the destination already exist, to verify if they are identical. This was the behaviour before 2.6. Since it downloads the md5 before (maybe) downloading the artifact, and since some repository software, when acting as a proxy/cache, return a 404 error if the artifact has not been cached yet, it may fail unexpectedly. If you still need it, you should consider using always instead - if you deal with a checksum, it is better to use it to verify integrity after download.
always combines download and change.
version
string
The maven version coordinate
Mutually exclusive with version_by_spec.
version_by_spec
string
added in 0.2.0 of community.general
The maven dependency version ranges.
The range type "(,1.0],[1.2,)" and "(,1.1),(1.1,)" is not supported.
Mutually exclusive with version.

Examples

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

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

- name: Download an artifact from a private repository requiring authentication
  community.general.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

- name: Download an artifact from a private repository requiring certificate authentication
  community.general.maven_artifact:
    group_id: com.company
    artifact_id: library-name
    repository_url: 'https://repo.company.com/maven'
    client_cert: /path/to/cert.pem
    client_key: /path/to/key.pem
    dest: /tmp/library-name-latest.jar

- name: Download a WAR File to the Tomcat webapps directory to be deployed
  community.general.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

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

- name: Download the latest version of the JUnit framework artifact from Maven local
  community.general.maven_artifact:
    group_id: junit
    artifact_id: junit
    dest: /tmp/junit-latest.jar
    repository_url: "file://{{ lookup('env','HOME') }}/.m2/repository"

- name: Download the latest version between 3.8 and 4.0 (exclusive) of the JUnit framework artifact from Maven Central
  community.general.maven_artifact:
    group_id: junit
    artifact_id: junit
    version_by_spec: "[3.8,4.0)"
    dest: /tmp/

Authors

  • Chris Schmidt (@chrisisbeef)