0

For some reason this fails:

- name: "Get GPG key from the Jenkins portal"
  get_url:
    url: https://pkg.jenkins.io/debian-stable/jenkins.io.key
    dest: /usr/share/keyrings/jenkins.io.key
- name: "Delete existing keys and de-arm"
  become: true
  shell: |
     "rm -rf /usr/share/keyrings/jenkins.gpg"
     "gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key"

This is a part of a tasks file that gets called from another file. I do not see why the first should fail. The failure reason is:

fatal: [localhost]: FAILED! => {
    "changed": true,
    "cmd": "\"rm -rf /usr/share/keyrings/jenkins.gpg\"\n\"gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key\"\n",
    "delta": "0:00:00.021351",
    "end": "2023-02-07 12:00:17.975367",
    "invocation": {
        "module_args": {
            "_raw_params": "\"rm -rf /usr/share/keyrings/jenkins.gpg\"\n\"gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key\"\n",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true
        }
    },
    "msg": "non-zero return code",
    "rc": 127,
    "start": "2023-02-07 12:00:17.954016",
    "stderr": "/bin/sh: 1: rm -rf /usr/share/keyrings/jenkins.gpg: not found\n/bin/sh: 2: gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key: not found",
    "stderr_lines": [
        "/bin/sh: 1: rm -rf /usr/share/keyrings/jenkins.gpg: not found",
        "/bin/sh: 2: gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key: not found"
    ],
    "stdout": "",
    "stdout_lines": []
}

I don't know what not found means in this context. I can run these very commands in sequence on a real shell and they work.

- name: "Get GPG key from the Jenkins portal"
  get_url:
    url: https://pkg.jenkins.io/debian-stable/jenkins.io.key
    dest: /usr/share/keyrings/jenkins.io.key
- name: "Delete existing key"
  become: true
  shell: "rm -rf /usr/share/keyrings/jenkins.gpg"
- name: "De-arm the keys"
  become: true
  shell: "gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key"
  register: jenkinskey

Since these get processed via the shell, they should be fine I believe.

Any hints?

1 Answer 1

1

I do not see why the first should fail.

It looks like the task has a syntax error

- name: "Delete existing keys and de-arm"
  become: true
  shell: |
     "rm -rf /usr/share/keyrings/jenkins.gpg"
     "gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key"

According the error message

    "stderr": "/bin/sh: 1: rm -rf /usr/share/keyrings/jenkins.gpg: not found\n/bin/sh: 2: gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key: not found",
    "stderr_lines": [
        "/bin/sh: 1: rm -rf /usr/share/keyrings/jenkins.gpg: not found",
        "/bin/sh: 2: gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key: not found"

The lines are processed as one single command and if I interpret it correctly. Furthermore, no quotes are necessary.

I don't know what not found means in this context.

It means that the command as a whole or parts of it wasn't found, a syntax error and is the expected behavior.

Possible Solution

You could try with

  - name: Exec sh script on Remote Node
    shell:
      cmd: |
        rm -f /usr/share/keyrings/jenkins.gpg
        gpg --dearmor -o /usr/share/keyrings/jenkins.gpg /usr/share/keyrings/jenkins.io.key
    register: result

or even with

    shell: "rm -f /usr/share/keyrings/jenkins.gpg && gpg --dearmor -o /usr/share/keyrings/jenkins.gpg"

Similar Q&A

Further Recommendation

Instead of using the shell module implement the commands with Ansible modules

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.