|
| 1 | +--- |
| 2 | +# This playbook should only be run against a teuthology host or a machine inside the Sepia test lab that can lock testnodes. |
| 3 | +# See ceph-cm-ansible/README.rst |
| 4 | + |
| 5 | +- hosts: all |
| 6 | + become: true |
| 7 | + user: cm |
| 8 | + vars: |
| 9 | + - jenkins_user: 'jenkins-build' |
| 10 | + # jenkins API credentials: |
| 11 | + - api_user: 'ceph-jenkins' |
| 12 | + - token: '{{ token }}' |
| 13 | + - api_uri: 'https://jenkins.ceph.com' |
| 14 | + - jenkins_credentials_uuid: '39fa150b-b2a1-416e-b334-29a9a2c0b32d' |
| 15 | + - nodename: 'teuthology' |
| 16 | + - labels: 'teuthology' |
| 17 | + |
| 18 | + tasks: |
| 19 | + - name: "create a {{ jenkins_user }} user" |
| 20 | + user: |
| 21 | + name: "{{ jenkins_user }}" |
| 22 | + append: yes |
| 23 | + comment: "Jenkins Build Slave User" |
| 24 | + |
| 25 | + - name: "create a {{ jenkins_user }} home directory" |
| 26 | + file: |
| 27 | + path: "/home/{{ jenkins_user }}/" |
| 28 | + state: directory |
| 29 | + owner: "{{ jenkins_user }}" |
| 30 | + |
| 31 | + - name: Create .ssh directory |
| 32 | + file: |
| 33 | + path: "/home/{{ jenkins_user }}/.ssh" |
| 34 | + state: directory |
| 35 | + owner: "{{ jenkins_user }}" |
| 36 | + |
| 37 | + - name: set the authorized keys |
| 38 | + authorized_key: |
| 39 | + user: "{{ jenkins_user }}" |
| 40 | + key: "{{ lookup('file', 'files/ssh/keys/jenkins_build.pub') }}" |
| 41 | + |
| 42 | + - name: Write ~/.ssh/config |
| 43 | + blockinfile: |
| 44 | + path: "/home/{{ jenkins_user }}/.ssh/config" |
| 45 | + create: yes |
| 46 | + block: | |
| 47 | + Host * |
| 48 | + StrictHostKeyChecking no |
| 49 | + UserKnownHostsFile=/dev/null |
| 50 | +
|
| 51 | + - name: set utf-8 for LC_ALL |
| 52 | + lineinfile: |
| 53 | + dest: "/home/{{ jenkins_user }}/.bashrc" |
| 54 | + regexp: '^export LC_ALL=' |
| 55 | + line: "export LC_ALL=en_US.UTF-8" |
| 56 | + create: true |
| 57 | + state: present |
| 58 | + |
| 59 | + - name: set utf-8 for LANG |
| 60 | + lineinfile: |
| 61 | + dest: "/home/{{ jenkins_user }}/.bashrc" |
| 62 | + regexp: '^export LANG=' |
| 63 | + line: "export LANG=en_US.UTF-8" |
| 64 | + |
| 65 | + - name: set utf-8 for LANGUAGE |
| 66 | + lineinfile: |
| 67 | + dest: "/home/{{ jenkins_user }}/.bashrc" |
| 68 | + regexp: '^export LANGUAGE=' |
| 69 | + line: "export LANGUAGE=en_US.UTF-8" |
| 70 | + |
| 71 | + - name: ensure the build dir exists |
| 72 | + file: |
| 73 | + path: "/home/{{ jenkins_user }}/build" |
| 74 | + state: directory |
| 75 | + owner: "{{ jenkins_user }}" |
| 76 | + |
| 77 | + - name: ensure the home dir has the right owner permissions |
| 78 | + file: |
| 79 | + path: "/home/{{ jenkins_user }}" |
| 80 | + state: directory |
| 81 | + owner: "{{ jenkins_user }}" |
| 82 | + group: "{{ jenkins_user }}" |
| 83 | + recurse: yes |
| 84 | + |
| 85 | + - name: ensure the gitconfig file exists |
| 86 | + shell: printf "[user]\name=Ceph CI\[email protected]\n" > /home/{{ jenkins_user }}/.gitconfig |
| 87 | + |
| 88 | + - name: ensure the gitconfig file has right permissions |
| 89 | + file: |
| 90 | + path: "/home/{{ jenkins_user }}/.gitconfig" |
| 91 | + owner: "{{ jenkins_user }}" |
| 92 | + |
| 93 | + - name: install six, latest one |
| 94 | + pip: |
| 95 | + name: six |
| 96 | + state: latest |
| 97 | + |
| 98 | + - name: install python-jenkins |
| 99 | + # https://review.openstack.org/460363 |
| 100 | + pip: |
| 101 | + name: python-jenkins |
| 102 | + version: 0.4.15 |
| 103 | + |
| 104 | + - name: add github.com host key |
| 105 | + known_hosts: |
| 106 | + path: '/etc/ssh/ssh_known_hosts' |
| 107 | + # we need to use 'host' here because prado currently uses ansible-playbook==1.9.1 |
| 108 | + host: 'github.com' |
| 109 | + # github.com.pub is the output of `ssh-keyscan github.com` |
| 110 | + key: "{{ lookup('file', 'files/ssh/hostkeys/github.com.pub') }}" |
| 111 | + |
| 112 | + - name: register the new slave to jenkins master with jnlp |
| 113 | + jenkins_node: |
| 114 | + username: "{{ api_user }}" |
| 115 | + uri: "{{ api_uri }}" |
| 116 | + password: "{{ token }}" |
| 117 | + # relies on a convention to set a unique name that allows a reverse |
| 118 | + # mapping from Jenkins back to whatever service created the current |
| 119 | + # node |
| 120 | + name: "{{ ansible_default_ipv4.address }}+{{ nodename }}" |
| 121 | + labels: "{{ labels }}" |
| 122 | + host: "{{ ansible_default_ipv4.address }}" |
| 123 | + credentialsId: "{{ jenkins_credentials_uuid }}" |
| 124 | + launcher: 'hudson.slaves.JNLPLauncher' |
| 125 | + remoteFS: '/home/{{ jenkins_user }}/build' |
| 126 | + # XXX this should be configurable, not all nodes should have one executor |
| 127 | + executors: '{{ executors|default(1) }}' |
| 128 | + exclusive: true |
| 129 | + |
| 130 | + - name: Download slave.jar |
| 131 | + get_url: |
| 132 | + url: "{{ api_uri }}/jnlpJars/slave.jar" |
| 133 | + dest: "/home/{{ jenkins_user }}/slave.jar" |
| 134 | + force: yes |
| 135 | + |
| 136 | + - name: install the systemd unit file for jenkins |
| 137 | + template: |
| 138 | + src: "templates/systemd/jenkins.service.j2" |
| 139 | + dest: "/etc/systemd/system/jenkins.service" |
| 140 | + |
| 141 | + - name: start jenkins service |
| 142 | + service: |
| 143 | + name: jenkins |
| 144 | + state: started |
| 145 | + enabled: yes |
0 commit comments