# \`jenkins\_credential\` failed to add/update credentials with initial Jenkins password and poor documentation

**URL:** <https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702>\
**Category:** Get Help\
**Tags:** kubernetes, aws\
**Created:** [April 17, 2026, 3:45pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702 "2026-04-17T15:45:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tukykarmakar](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tukykarmakar](https://forum.ansible.com/u/tukykarmakar)\
**Post date:** [April 17, 2026, 3:45pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/1 "2026-04-17T15:45:26Z")

</div>

# Problem 1: `jenkins_credential` not working with Initial Jenkins Admin Password

I’m running Jenkins inside a Docker container and using playbooks to configure Jenkins with what I need. I’m using the initial Jenkins admin password to authenticate for installing plugins using the `jenkins_plugin` module.

However, when I tried adding credentials using `jenkins_credential` module, the playbook seems to be failing with the initial admin password, but working after I have configured new admin user and password.

The playbook for configuring credentials fails with the error message below, when attempting with initial admin password–

```auto
TASK [Add DockerHub credentials] *******************************************************************************************************************************************************
fatal: [52.66.252.99]: FAILED! => {"changed": false, "details": "", "msg": "Failed to add/update credential"}

```

Additionally, the module doesn’t seem to like using `jenkins_password` to add the credentials, and asks to use the `token` parameter for API token.

## Playbook for Adding Credentials

```yaml
---
# Fails with initial Jenkins admin password, but works with new admin password
- name: Configure Credentials in Jenkins
  hosts: jenkins
  vars_prompt:
    - name: dockerhub_username
      prompt: "Enter DockerHub username"
      private: no
    - name: dockerhub_password
      prompt: "Enter DockerHub password"
      private: yes
    - name: sonarqube_secret
      prompt: "Enter SonarQube token"
      private: yes

  tasks:
    - name: Retrieve initial Jenkins admin password
      shell: docker exec jenkins_container cat /var/jenkins_home/secrets/initialAdminPassword
      register: jenkins_password
      changed_when: false

    - name: Generate token
      community.general.jenkins_credential:
        url: "http://{{ ansible_host }}:{{ access_port }}" # vars defined in inventory
        id: "test-token"
        name: "test_token_name"
        jenkins_user: "admin"
        jenkins_password: "{{ jenkins_password.stdout }}"
        type: "token"
      register: token_result

    - name: Add DockerHub credentials
      community.general.jenkins_credential:
        url: "http://{{ ansible_host }}:{{ access_port }}" # vars defined in inventory
        jenkins_user: admin
        #jenkins_password: "{{ jenkins_password.stdout }}"
        token: "{{ token_result.token }}"
        id: "DockerHub-Credentials"
        type: "user_and_pass"
        description: "DockerHub Credentials"
        username: "{{ dockerhub_username }}"
        password: "{{ dockerhub_password }}"

    - name: Add SonarQube credentials
      community.general.jenkins_credential:
        url: "http://{{ ansible_host }}:{{ access_port }}"
        jenkins_user: admin
        #jenkins_password: "{{ jenkins_password.stdout }}"
        token: "{{ token_result.token }}"
        id: "SonarQube-Token"
        description: "SonarQube Token"
        type: "text"
        secret: "{{ sonarqube_secret }}"

```

## Playbook for installing plugins

```yaml
- name: Install Required Jenkins Plugins
  hosts: jenkins
  tasks:
    - name: Retrieve initial Jenkins admin password
      shell: docker exec jenkins_container cat /var/jenkins_home/secrets/initialAdminPassword
      register: jenkins_password
      changed_when: false

    - name: Install required Jenkins plugins
      community.general.jenkins_plugin:
        url: "http://{{ ansible_host }}:{{ access_port }}" # vars defined in inventory
        url_username: admin
        url_password: "{{ jenkins_password.stdout }}"
        name: "{{ item }}"
        state: present
        with_dependencies: true
      loop:
        - aws-credentials # AWS Credentials
        - config-file-provider # Config File Provider
        - docker-plugin # Docker
        - docker-workflow # Docker Pipeline
        - adoptopenjdk # Eclipse Temurin Installer
        - email-ext # Email Extension
        - htmlpublisher # HTML Publisher
        - kubernetes # Kubernetes
        - kubernetes-cli # Kubernetes CLI
        - maven-plugin # Maven Integration
        - nexus-artifact-uploader # Nexus Artifact Uploader
        - pipeline-maven # Pipeline Maven Integration
        - pipeline-aws # Pipeline: AWS Steps
        - sonar # SonarQube Scanner
      register: plugin_install
      when: jenkins_password is defined

    - name: Restart Jenkins for plugin activation
      docker_container:
        name: jenkins_container
        state: started
        restart: true
      when: plugin_install.changed

```

# Problem 2: Incorrect example playbook in documentation

Aside from authentication issue, I believe the `jenkins_credential` documentation page has a [poor/incorrect example](https://docs.ansible.com/projects/ansible/latest/collections/community/general/jenkins_credential_module.html#examples), where the parameter “`token: {{ token }}`” should be “`token: {{ token_result.token }}`”, if it were to work as a single playbook with the task that generated the token.

As written in my credentials playbook above, it’s working with `token: {{ token_result.token }}` syntax, when I have set my own admin password. I was getting errors with the syntax in the example playbook even when I had set my own admin password.

Where can I post about correcting the documentation? Or am I misinterpreting it?

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 17, 2026, 4:56pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/2 "2026-04-17T16:56:10Z")

</div>

- Problem 1  
The module documentation correctly tells you that jenkins\_username is always required, and that token is always required _except_ for `type: token` which requires jenkins\_password instead (the only time the password is required). The documentation also tells you that `name:` is required for `type: token` and that a new token will be generated everytime unless the `id:` is specified. In the RETURN section, it mentions that the actual token will only ever be returned _ **once** _. So you must record the api token securely to re-use it later or otherwise you will want to add a clean-up routine to delete old tokens.

- Problem 2  
You’re right that the documentation EXAMPLE isn’t consistent with the token syntax and should use `"{{ token_result.token }}"`, and the required `name: ` wasn’t specified either. Since the token id was specified though, then even if the rest of the code was correct, the example would only work on the first pass as only the token\_uuid instead of the token itself will be returned on subsequent runs.

The contributing guidelines for that collection is here: [community.general/CONTRIBUTING.md at main · ansible-collections/community.general · GitHub](https://github.com/ansible-collections/community.general/blob/main/CONTRIBUTING.md)  
That will point you to the issue tracker to create a bug report, but if you’re willing to update the documentation yourself then review the rest of the contributing guidelines about Opening a Pull Request.

---

<div class="post-metadata">

**Author:** ![tukykarmakar](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tukykarmakar](https://forum.ansible.com/u/tukykarmakar)\
**Post date:** [April 18, 2026, 5:37am UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/3 "2026-04-18T05:37:18Z")

</div>

Ok, I understood that it requires a token to add credentials. But, what I don’t understand is why the tasks of adding credentials is failing but token creation is succeeding when using the initial admin password.

What I’m trying to do is create the Docker container and configure Jenkins using Ansible playbooks _before_ I create my admin account. As such, I have to use the initial admin password to do that.

If my playbook was not storing the token properly, or a duplicate token can’t be created, then it’d also fail after creating the new admin user/password. I ran the playbook multiple times before creating new admin, but it succeeds on the first try after it.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 20, 2026, 4:44pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/4 "2026-04-20T16:44:54Z")

</div>

So a couple questions, when you initialize Jenkins and run the setup wizard, do you create any users before finishing the setup? Were any of them created as admins?

Does removing this one line from your playbook make any difference?

```diff
    - name: Generate token
      community.general.jenkins_credential:
        url: "http://{{ ansible_host }}:{{ access_port }}" # vars defined in inventory
- id: "test-token"
        name: "test_token_name"
        jenkins_user: "admin"
        jenkins_password: "{{ jenkins_password.stdout }}"
        type: "token"
      register: token_result

```

---

<div class="post-metadata">

**Author:** ![tukykarmakar](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tukykarmakar](https://forum.ansible.com/u/tukykarmakar)\
**Post date:** [April 21, 2026, 3:40pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/5 "2026-04-21T15:40:31Z")

</div>

I have a playbook to only run the Jenkins container mounting necessary volumes and providing necessary permissions. I’m running the credentials playbook before opening the Jenkins URL (http://:8080). Same with the plugins playbook.

Removing the `id: "test-token"` line didn’t make any difference. Same behaviour as before: token generation succeeds but task for adding new credentials fails.

 ![Playbook execution output](https://us1.discourse-cdn.com/ansible/original/2X/5/5c89fe121fdc89b9d77f613478150107344935d0.png)

For reference, the playbook for creating the Jenkins container is below–

```yaml
---
- name: Deploy Jenkins container
  hosts: jenkins
  vars:
    jenkins_image: jenkins/jenkins:slim
  pre_tasks:
    - name: Get host Docker group GID
      shell: "getent group docker | cut -d: -f3"
      register: docker_gid
      changed_when: false
  tasks:
    - name: Run Jenkins container
      docker_container:
        name: jenkins_container
        image: "{{ jenkins_image }}"
        groups:
          - "{{ docker_gid.stdout }}"
        ports:
          - "{{ access_port }}:8080"
        volumes:
          - jenkins_home:/var/jenkins_home
          # Give Jenkins container access to host Docker
          - /var/run/docker.sock:/var/run/docker.sock
          - /usr/bin/docker:/usr/bin/docker:ro
        state: started
        restart_policy: unless-stopped

```

---

<div class="post-metadata">

**Author:** ![tukykarmakar](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tukykarmakar](https://forum.ansible.com/u/tukykarmakar)\
**Post date:** [May 11, 2026, 12:49pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/6 "2026-05-11T12:49:42Z")

</div>

I haven’t found any answer about why this module fails with the initial Jenkins admin credentials. But I’ve managed to raise and merge a [PR](https://github.com/ansible-collections/community.general/pull/11922) that corrects the errors and improves some parts of the documentation.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [May 13, 2026, 6:47pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/7 "2026-05-13T18:47:33Z")

</div>

Got around to doing some local testing.

I was able to reproduce your error with creating credentials when I followed this process:

1. Deploy fresh container (Jenkins is locked)
2. Attempt to add credentials (error)

I was able to work around the issue by installing your required plugins first:

1. Deploy fresh container (Jenkins is locked)
2. Install plugins (success)
3. Add credentials (success)

When doing this manually (instead of via Ansible), you must unlock Jenkins first, but you can exit the wizard afterwards without installing any plugins or adding any users. This takes you to the Jenkins Dashboard as the default admin, but you cannot add credentials because not even the credential plugin is included in the base docker image.

---

<div class="post-metadata">

**Author:** ![tukykarmakar](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tukykarmakar](https://forum.ansible.com/u/tukykarmakar)\
**Post date:** [May 15, 2026, 2:35pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/8 "2026-05-15T14:35:44Z")

</div>

Yeah, that makes sense. I checked the plugins that are being installed during initial setup and found that it installs [Credentials Binding plugin](https://plugins.jenkins.io/credentials-binding/).

 ![image](https://us1.discourse-cdn.com/ansible/original/2X/3/3fab229ce5757a8080a958722c944adcf5e04cc8.png)

Theoretically, I should be able to install the plugin using the Ansible play task and then the `jenkins_credential` module should also work. Thanks!

---

<div class="post-metadata">

**Author:** ![tukykarmakar](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tukykarmakar](https://forum.ansible.com/u/tukykarmakar)\
**Post date:** [May 16, 2026, 12:49pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/9 "2026-05-16T12:49:10Z")

</div>

I tested and found that it indeed works if I install the Credentials Binding plugin before running the task of adding credentials.

I simply added the required plugin to the list in the task, and then ran the credentials task after completion of plugin installation. It worked without issues.

Thanks @Denney-tech for pointing out the missing plugin!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 15, 2026, 12:49pm UTC](https://forum.ansible.com/t/jenkins-credential-failed-to-add-update-credentials-with-initial-jenkins-password-and-poor-documentation/45702/10 "2026-06-15T12:49:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
