Last-modified: 2020-12-12 (土) 19:51:16 (1220d)
 

Jenkinsの導入

 Jenkinsは、どのような方式でも導入は簡単ですが、本件では公式RPMで導入する。RPMで導入すると、Jenkinsの更新をyumコマンドで実施完了してしまえるメリットがある。

導入サーバの前提条件

  1. OSはRHEL8(or RHEL7)とする。 ※Java8以上が動けばなんでもよい
  2. 事前導入するソフトウェアパッケージは最小構成。
  3. インターネットに接続可能 ※必要ならproxy設定
     /etc/dnf/dnf.conf
    proxy=http://proxy.jomura.net:8080/     #as your own
     ~/.bashrc
    export HTTP_PROXY=http://proxy.jomura.net:8080/     #as your own
    export HTTPS_PROXY=${HTTP_PROXY}
  4. パッケージの更新が事前に実行されている
    dnf clean all && dnf -y update && reboot
  5. Jenkins Webサイト用のFully Qualified Domain Name(FQDN)が用意されている。

playbookの作成

  • Ansibleサーバ上の一般ユーザで実行
  • sudoの場合、become_method: sudo
    cat << "_EOF_" > pb_jenkins_server.yml
    # install jenkins
    
    - hosts: jenkins_servers
      become: true
      become_method: su
      environment: "{{ proxy_env }}"
    
      tasks:
        - name: facts check
          fail:
            msg: "Not compatible with [{{ ansible_os_family }}] {{ ansible_distribution }} {{ ansible_distribution_major_version }}."
          when: ansible_os_family != 'RedHat' or ansible_distribution_major_version|int < 7
    
        - name: jenkins repository
          yum_repository:
            name: jenkins
            description: jenkins repos
            baseurl: "http://pkg.jenkins.io/redhat-stable/"
    
        - name: jenkins.io key installed
          rpm_key:
            key: "http://pkg.jenkins.io/redhat-stable/jenkins.io.key"
    
        - name: "Jenkins installed"
          dnf:
            name: 
              - java-11-openjdk
              - jenkins
            state: latest
    
        - name: port forward
          shell: firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080 --permanent
          register: result
          changed_when: '"Warning: ALREADY_ENABLED: " not in result.stderr'
          notify: reload firewalld
    
        - name: restart jenkins
          systemd:
            name: jenkins
            state: restarted
            daemon_reload: yes
            enabled: yes
    
      handlers:
    
        - name: reload firewalld
          service: name=firewalld state=restarted
    
    _EOF_
  • Java11
  • Jenkins自体はtcp:8080で稼働し、firewalldでtcp:80からforwardさせる

playbookの実行

  • Ansibleサーバ上の一般ユーザで実行する。
    ansible-playbook -i inventory.yml pb_jenkins_server.yml

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS