Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maven_artifact can't get artifact from local repo. #29334

Closed
ansibot opened this issue Sep 11, 2017 · 11 comments · Fixed by #36159
Closed

maven_artifact can't get artifact from local repo. #29334

ansibot opened this issue Sep 11, 2017 · 11 comments · Fixed by #36159
Labels
affects_2.0 This issue/PR affects Ansible v2.0 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community.

Comments

@ansibot
Copy link
Contributor

ansibot commented Sep 11, 2017

From @chchrist on 2016-07-11T11:55:05Z

ISSUE TYPE
  • Bug Report
COMPONENT NAME

maven_artifact

ANSIBLE VERSION
ansible 2.0.2.0
CONFIGURATION
OS / ENVIRONMENT

N/A

SUMMARY

maven_artifact can't get artifact from local repo as is looking for maven-metadata.xml and locally is maven-metadata-local.xml

STEPS TO REPRODUCE

Just try to point to your local maven repository.

- name: get artifact from local repo
  local_action: maven_artifact
  args:
    group_id: acme
    artifact_id: cms
    extension: zip
    classifier: foo
    version: "{{ artifact_version }}"
    repository_url: "~/.m2/repository"
    state: present
    dest: /tmp
  register: artifact
EXPECTED RESULTS

It should be able to find the maven-metadata-local.xml

ACTUAL RESULTS
"msg": "unknown url type: ~/.m2/repository/acme/foo/cms/1.10-SNAPSHOT/maven-metadata.xml"}

Copied from original issue: ansible/ansible-modules-extras#2547

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @alikins on 2016-07-11T11:55:05Z

Is the behavior any different if repository_url is a file url? like:

- name: get artifact from local repo
  local_action: maven_artifact
  args:
    group_id: acme
    artifact_id: cms
    extension: zip
    classifier: foo
    version: "{{ artifact_version }}"
    repository_url: "file:///home/username/.m2/repository"
    state: present
    dest: /tmp
  register: artifact

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @ansibot on 2016-07-11T11:55:05Z

@chchrist ping, this issue is still waiting on your feedback. We will close the issue if you do not respond.
click here for bot help

2 similar comments
@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @ansibot on 2016-07-11T11:55:05Z

@chchrist ping, this issue is still waiting on your feedback. We will close the issue if you do not respond.
click here for bot help

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @ansibot on 2016-07-11T11:55:05Z

@chchrist ping, this issue is still waiting on your feedback. We will close the issue if you do not respond.
click here for bot help

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @chchrist on 2016-07-11T11:55:05Z

@alikins I haven' tried it. I will try and come back to you.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @ktakashi on 2016-07-11T11:55:05Z

I've tried the file:// prefix and got the error like this:

fatal: [machine]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to download maven-metadata.xml because of Request failed: <urlopen error [Errno 2] No such file or directory: '/home/takashi/.m2/repository/.../maven-metadata.xml'>for URL file:///home/takashi/.m2/repository/.../maven-metadata.xml"}

In the repository directory there's maven-metadata-local.xml but no maven-metadata.xml

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @clabu on 2016-07-11T11:55:05Z

This was working using the file:// prefix in Ansible 2.0.1.0 but it was broken by this change in lib/ansible/module_utils/uris.py introduced in Ansible 2.1.0.0: ed35e8b

Previously, the urls.fetch_url method would always set the response's status code to 200. Since the change, the actual status code in the response is used. For a "file://" URLs there is no (HTTP) status code in the response, so it gets set to value NoneType instead of 200. The result is that the status code-check in maven_artifact._request thinks the URL request failed: https://github.com/ansible/ansible-modules-extras/blob/6c7d63b15c77126b4d6a8a7668545555578469c5/packaging/language/maven_artifact.py#L282

This patch to maven_artifact.py line 282 copes with the NoneType for file:// URLs:

        if info['status'] == 200 or (info['status'] == None and parsed_url.scheme == 'file'):
            return f(response)
        else:
            raise ValueError(failmsg + " because of " + info['msg'] + "for URL " + url_to_use)

If you consider the fix robust enough, I will make a pull request.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @petenorth on 2016-07-11T11:55:05Z

@clabu The patch to maven_artifact.py didn't resolve the issue for me.

The info['status'] seems to come back with -1, I tried using a value of -1 rather than None but to no avail.

Version of ansible was:

ansible 2.3.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

Error I got when I changed info['status'] == None to info['status'] == -1

failed: [node1.example.com] (item={u'version': u'1.1.0-SNAPSHOT', u'groupId': u'com.redhat.camel', u'artifactId': u'camel-amq-consumer'}) => {"failed": true, "item": {"artifactId": "camel-amq-consumer", "groupId": "com.redhat.camel", "version": "1.1.0-SNAPSHOT"}, "module_stderr": "Shared connection to node1.example.com closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File "/tmp/ansible_MMTYaR/ansible_module_maven_artifact.py", line 424, in \r\n main()\r\n File "/tmp/ansible_MMTYaR/ansible_module_maven_artifact.py", line 414, in main\r\n if downloader.download(artifact, dest):\r\n File "/tmp/ansible_MMTYaR/ansible_module_maven_artifact.py", line 294, in download\r\n url = self.find_uri_for_artifact(artifact)\r\n File "/tmp/ansible_MMTYaR/ansible_module_maven_artifact.py", line 244, in find_uri_for_artifact\r\n xml = self._request(self.base + path, "Failed to download maven-metadata.xml", lambda r: etree.parse(r))\r\n File "/tmp/ansible_MMTYaR/ansible_module_maven_artifact.py", line 283, in _request\r\n return f(response)\r\n File "/tmp/ansible_MMTYaR/ansible_module_maven_artifact.py", line 244, in \r\n xml = self._request(self.base + path, "Failed to download maven-metadata.xml", lambda r: etree.parse(r))\r\n File "lxml.etree.pyx", line 3197, in lxml.etree.parse (src/lxml/lxml.etree.c:64816)\r\n File "parser.pxi", line 1596, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:92968)\r\nTypeError: cannot parse from 'NoneType'\r\n", "msg": "MODULE FAILURE", "rc": 1}

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

@ansibot ansibot added affects_2.0 This issue/PR affects Ansible v2.0 bug_report module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. labels Sep 11, 2017
@SixRQ
Copy link

SixRQ commented Jan 10, 2018

I get the following error with 2.4.0.0

fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to download artifact com.example:myproject:0.0.525 because of OK (1329468 bytes)for URL file:///home/user/.m2/repository/com/example/myproject/0.0.525/myproject-0.0.525.jar"}

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@ansibot
Copy link
Contributor Author

ansibot commented Mar 17, 2018

cc @turb
click here for bot help

gmaes pushed a commit to gmaes/ansible that referenced this issue Mar 28, 2018
ryancurrah pushed a commit to ryancurrah/ansible that referenced this issue Apr 4, 2018
ilicmilan pushed a commit to ilicmilan/ansible that referenced this issue Nov 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.0 This issue/PR affects Ansible v2.0 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants