community.general.maven_artifact (8.5.0) — module

Downloads an Artifact from a Maven Repository

Authors: Chris Schmidt (@chrisisbeef)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

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

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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/

Inputs

    
dest:
    description:
    - 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
    required: true
    type: path

mode:
    description:
    - The permissions the resulting filesystem object should have.
    - For those used to I(/usr/bin/chmod) remember that modes are actually octal numbers.
      You must give Ansible enough information to parse them correctly. For consistent
      results, quote octal numbers (for example, V('644') or V('1777')) so Ansible receives
      a string and can do its own conversion from string into number. Adding a leading
      zero (for example, V(0755)) works sometimes, but can fail in loops and some other
      circumstances.
    - Giving Ansible a number without following either 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, V(u+rwx)
      or V(u=rw,g=r,o=r)).
    - If O(mode) is not specified and the destination filesystem object B(does not) exist,
      the default C(umask) on the system will be used when setting the mode for the newly
      created filesystem object.
    - If O(mode) is not specified and the destination filesystem object B(does) exist,
      the mode of the existing filesystem object will be used.
    - Specifying O(mode) is the best way to ensure filesystem objects are created with
      the correct permissions. See CVE-2020-1736 for further details.
    type: raw

group:
    description:
    - Name of the group that should own the filesystem object, as would be fed to I(chown).
    - When left unspecified, it uses the current group of the current user unless you
      are root, in which case it can preserve the previous ownership.
    type: str

owner:
    description:
    - Name of the user that should own the filesystem object, as would be fed to I(chown).
    - When left unspecified, it uses the current user unless you are root, in which case
      it can preserve the previous ownership.
    - Specifying a numeric username will be assumed to be a user ID and not a username.
      Avoid numeric usernames to avoid this confusion.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - The desired state of the artifact
    type: str

serole:
    description:
    - The role part of the SELinux filesystem object context.
    - When set to V(_default), it will use the C(role) portion of the policy if available.
    type: str

setype:
    description:
    - The type part of the SELinux filesystem object context.
    - When set to V(_default), it will use the C(type) portion of the policy if available.
    type: str

seuser:
    description:
    - The user part of the SELinux filesystem object context.
    - By default it uses the V(system) policy, where applicable.
    - When set to V(_default), it will use the C(user) portion of the policy if available.
    type: str

headers:
    description:
    - Add custom HTTP headers to a request in hash/dict format.
    type: dict

selevel:
    description:
    - The level part of the SELinux filesystem object context.
    - This is the MLS/MCS attribute, sometimes known as the C(range).
    - When set to V(_default), it will use the C(level) portion of the policy if available.
    type: str

timeout:
    default: 10
    description:
    - Specifies a timeout in seconds for the connection attempt
    type: int

version:
    description:
    - The maven version coordinate
    - Mutually exclusive with O(version_by_spec).
    type: str

group_id:
    description:
    - The Maven groupId coordinate
    required: true
    type: str

password:
    aliases:
    - aws_secret_access_key
    description:
    - The password to authenticate with to the Maven Repository. Use AWS secret access
      key of the repository is hosted on S3
    type: str

username:
    aliases:
    - aws_secret_key
    description:
    - The username to authenticate as to the Maven Repository. Use AWS secret key of the
      repository is hosted on S3
    type: str

extension:
    default: jar
    description:
    - The maven type/extension coordinate
    type: str

keep_name:
    default: false
    description:
    - If V(true), the downloaded artifact's name is preserved, i.e the version number
      remains part of it.
    - This option only has effect when O(dest) is a directory and O(version) is set to
      V(latest) or O(version_by_spec) is defined.
    type: bool

attributes:
    aliases:
    - attr
    description:
    - The attributes the resulting filesystem object should have.
    - To get supported flags look at the man page for I(chattr) on the target system.
    - This string should contain the attributes in the same order as the one displayed
      by I(lsattr).
    - The C(=) operator is assumed as default, otherwise C(+) or C(-) operators need to
      be included in the string.
    type: str
    version_added: '2.3'
    version_added_collection: ansible.builtin

classifier:
    default: ''
    description:
    - The maven classifier coordinate
    type: str

client_key:
    description:
    - PEM formatted file that contains your private key to be used for SSL client authentication.
    - If O(client_cert) contains both the certificate and key, this option is not required.
    type: path
    version_added: 1.3.0
    version_added_collection: community.general

artifact_id:
    description:
    - The maven artifactId coordinate
    required: true
    type: str

client_cert:
    description:
    - 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, O(client_key)
      is not required.
    type: path
    version_added: 1.3.0
    version_added_collection: community.general

checksum_alg:
    choices:
    - md5
    - sha1
    default: md5
    description:
    - If V(md5), checksums will use the MD5 algorithm. This is the default.
    - If V(sha1), checksums will use the SHA1 algorithm. This can be used on systems configured
      to use FIPS-compliant algorithms, since MD5 will be blocked on such systems.
    type: str
    version_added: 3.2.0
    version_added_collection: community.general

unsafe_writes:
    default: false
    description:
    - Influence when to use atomic operation to prevent data corruption or inconsistent
      reads from the target filesystem object.
    - By default this module uses atomic operations to prevent data corruption or inconsistent
      reads from the target filesystem objects, but sometimes systems are configured or
      just broken in ways that prevent this. One example is docker mounted filesystem
      objects, 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 filesystem
      objects 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.
    type: bool
    version_added: '2.2'
    version_added_collection: ansible.builtin

directory_mode:
    description:
    - Filesystem permission mode applied recursively to O(dest) when it is a directory.
    type: str

repository_url:
    default: https://repo1.maven.org/maven2
    description:
    - 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
    type: str

validate_certs:
    default: true
    description:
    - If V(false), SSL certificates will not be validated. This should only be set to
      V(false) when no other option exists.
    type: bool

verify_checksum:
    choices:
    - never
    - download
    - change
    - always
    default: download
    description:
    - If V(never), the MD5/SHA1 checksum will never be downloaded and verified.
    - If V(download), the MD5/SHA1 checksum will be downloaded and verified only after
      artifact download. This is the default.
    - If V(change), the MD5/SHA1 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 checksum 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 V(always) instead - if you deal with a checksum, it is
      better to use it to verify integrity after download.
    - V(always) combines V(download) and V(change).
    required: false
    type: str

version_by_spec:
    description:
    - The maven dependency version ranges.
    - See supported version ranges on U(https://cwiki.apache.org/confluence/display/MAVENOLD/Dependency+Mediation+and+Conflict+Resolution)
    - The range type "(,1.0],[1.2,)" and "(,1.1),(1.1,)" is not supported.
    - Mutually exclusive with O(version).
    type: str
    version_added: 0.2.0
    version_added_collection: community.general

force_basic_auth:
    default: false
    description:
    - 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.
    type: bool
    version_added: 0.2.0
    version_added_collection: community.general

unredirected_headers:
    description:
    - A list of headers that should not be included in the redirection. This headers are
      sent to the C(fetch_url) function.
    - On ansible-core version 2.12 or later, the default of this option is V([Authorization,
      Cookie]).
    - Useful if the redirection URL does not need to have sensitive headers in the request.
    - Requires ansible-core version 2.12 or later.
    elements: str
    type: list
    version_added: 5.2.0
    version_added_collection: community.general