Create Jenkins Job using Ansible

Here is the sample playbook to list the Jenkins jobs.

---
- hosts: 127.0.0.1
  connection: local
  gather_facts: no
  vars:
    url: 'http://192.168.16.7:8080'
    file_name: "{{ url | basename }}"
    username: 'test'
    password: 'test'

  tasks:
    - name: make REST call
      jenkins_job_info:
        url: "{{ url }}"
        token: 126df5c60d66c66e3b75b11104a16a8a
        validate_certs: False
      register: message

    - name: Respone from restapi
      debug:
        msg="{{ message }}"

To run this Ansible playbook we need to change URL and username & password.

close this repo to local (https://github.com/sfgroups/jenkins-pipeline-library)


git clone https://github.com/sfgroups/jenkins-pipeline-library

Run the docker container and run the playbook

docker run --rm -it \
        --name ansible \
        -v $(pwd):/playbooks \
        sfgroups/ansible-python3

Run the ansible playbook

ansible-playbook  -i hosts  jenkins_jobs.yaml

Copyright © 2004, Software Groups