项目作者: DovnarAlexander

项目描述 :
Ansible Jenkins role
高级语言: Python
项目地址: git://github.com/DovnarAlexander/ansible-jenkins.git
创建时间: 2018-02-12T13:16:57Z
项目社区:https://github.com/DovnarAlexander/ansible-jenkins

开源协议:MIT License

下载


Build Status
Ansible Galaxy
MIT licensed

DovnarAlexander/jenkins

Ansible Galaxy DovnarAlexander/jenkins

This role helps you to install any version of Jenkins (LTS and Not).
It manages:

  • Jenkins users;
  • Credentials (SSH including key generation, Secret Text and Username-Password);
  • Installs plugins;
  • Jenkins Slaves (JNLP and SSH);
  • Some Jenkins main configuration (the main Hostname and Email).
  • You can manage as much as possible when you do not have direct SSH connection to Jenkins with “Remote_Jenkins” tag.

Role Variables

Jenkins Version

  1. # file: defaults/main.yml
  2. # Do you want install Jenkins from stable rep or not
  3. jenkins_stable: True

If you want to install non-LTS version - set it to False.

  1. # file: defaults/main.yml
  2. # What version should be installed
  3. jenkins_version: latest

If you want to install some specific version - input full version here (x.xx.x)

  1. # file: defaults/main.yml
  2. # Do you want to updated the Jenkins (if older version has been already installed)
  3. jenkins_update: False

If you do not want to update the version to the latest - set it to True.

Jenkins Configuration

  1. # file: defaults/main.yml
  2. # Jenkins HTTP port
  3. jenkins_http_port: 8080

You can change the default HTTP port here.

  1. # file: defaults/main.yml
  2. # Jenkins Home path
  3. jenkins_home: /var/lib/jenkins

You can change default Jenkins Home path here.

  1. # file: defaults/main.yml
  2. # Jenkins External Hostname for main configuration
  3. jenkins_notification_hostname: 'http://{{ inventory_hostname }}:{{ jenkins_http_port }}/'

You can set external Jenkins Hostname here manually.

  1. # file: defaults/main.yml
  2. # Jenkins EEmail for main configuration
  3. jenkins_notification_email: 'admin@example.com'

You can set Jenkins Notification Email here.

Jenkins Admin

  1. # file: defaults/main.yml
  2. # Jenkins New Admin details
  3. jenkins_admin:
  4. id: jenkins
  5. password: jenkins

By default it is a not good idea to use default admin credentials.
If you insist - you can change id to ‘admin’ and password for anything you want.

  1. # file: defaults/main.yml
  2. # Jenkins admin token location
  3. jenkins_admin_token_file: '{{ jenkins_home }}/secrets/admin_token'

You can specify local place to store Jenkins Admin token.

Jenkins Configuration

  1. # file: defaults/main.yml
  2. # List of required users to create
  3. # jenkins_users:
  4. # -
  5. # id: test-user
  6. # email: test-user@gmail.com
  7. # password: test-user
  8. jenkins_users: []

You can create the required amount of users using this list of dicts.

  1. # file: defaults/main.yml
  2. # List of required Jenkins plugins to install
  3. jenkins_plugins:
  4. - git
  5. - workflow-aggregator
  6. - jobConfigHistory
  7. - ssh
  8. - ssh-slaves
  9. - mailer

The list of Jenkins plugins which should be installed during installation.

  1. # file: defaults/main.yml
  2. # List of Nodes to create\configure
  3. # jenkins_nodes:
  4. # -
  5. # name: master
  6. # type: master
  7. # labels: master
  8. # executors: 7
  9. # -
  10. # name: test-jnlp
  11. # executors: 1
  12. # labels: test-jnlp
  13. # type: jnlp
  14. # home_path: /home/jenkins
  15. # description: 'test-jnlp'
  16. # -
  17. # name: test-ssh
  18. # executors: 1
  19. # labels: test-ssh
  20. # type: ssh
  21. # external_host: 127.0.0.1
  22. # credentials: jenkins-local-slave
  23. # home_path: '/var/lib/jenkins'
  24. # description: 'test-ssh'
  25. # environment:
  26. # FOO: bar
  27. # BAR: foo
  28. jenkins_nodes: []

You can create the required slaves using this variable. It also helps to change number of executors for every slave and to manage environment variables for the slaves.

  1. # file: defaults/main.yml
  2. # Jenkins user-password pairs credentials
  3. # jenkins_userpass_credentials:
  4. # -
  5. # id: test-credentials
  6. # description: "For test"
  7. # username: test-credentials-user
  8. # password: test-credentials-password
  9. jenkins_userpass_credentials: []

Using this list of dicts you can create all required username-password pair credentials.

  1. # file: defaults/main.yml
  2. # Jenkins secret-text credentials
  3. # jenkins_secret_text_credentials:
  4. # -
  5. # id: test-text-credentials
  6. # description: "For test"
  7. # secret_text: test-text-credentials
  8. jenkins_secret_text_credentials: []

Using this list of dicts you can create all required secret text credentials.

  1. # file: defaults/main.yml
  2. # Jenkins SSH credentials
  3. # jenkins_ssh_credentials:
  4. # -
  5. # id: test-ssh-user
  6. # username: test-ssh-user
  7. # print: True
  8. # description: "For test"
  9. # -
  10. # id: jenkins-local-slave
  11. # username: jenkins
  12. # local: True
  13. # description: "For test"
  14. jenkins_ssh_credentials: []

Using this list of dicts you can create all required SSH credentials.

Jenkins Configuration (unchangable)

  1. # file: defaults/main.yml
  2. # Required Python Pip packages
  3. pip_packages:
  4. - setuptools
  5. - lxml
  6. - python-jenkins
  7. - pyopenssl
  8. - urllib3

The list of Python Pip packages to install.

  1. # file: defaults/main.yml
  2. # Pip index URL
  3. pip_index_url: https://pypi.python.org/simple/

Full URL to pipy installation simple repository.

Jenkins Process Linux owner.

  1. # file: defaults/main.yml
  2. # Jenkins system user
  3. jenkins_system_user: jenkins

Jenkins Process Linux owner.

Example Playbook

Step 1: add role

Add role name DovnarAlexander.jenkins to your playbook file.

Step 2: if java is not installed on the target host you can use

If you want to install Java using DovnarAlexander/oracle-java playbook - install it with requirements.yml

  1. ansible-galaxy install DovnarAlexander.oracle-java

Step 3: add variables

If you need - modify variables your playbook\variables file.

Simple example:

  1. ---
  2. # file: simple-playbook.yml
  3. - hosts: all
  4. roles:
  5. - DovnarAlexander.oracle-java
  6. - DovnarAlexander.jenkins
  7. vars:
  8. jenkins_version: 2.60.3
  9. jenkins_plugins:
  10. - git
  11. - workflow-aggregator
  12. - jobConfigHistory
  13. - ssh
  14. - ssh-slaves
  15. - powershell

Step 4: add jenkins group in your inventory file

  1. ---
  2. # file:inventory.ini
  3. [jenkins]
  4. your_host
  5. [java:children]
  6. jenkins
  1. java:
  2. children:
  3. jenkins:
  4. hosts:
  5. your_host: