From: David Galloway Date: Fri, 4 Aug 2017 19:34:33 +0000 (-0400) Subject: ansible: Manage Jenkins auth with github-oauth X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=44b9d2154546cd9e32d8c5582cef2b394b33c347;p=ceph-build.git ansible: Manage Jenkins auth with github-oauth Signed-off-by: David Galloway --- diff --git a/ansible/roles/ansible-jenkins/tasks/auth.yml b/ansible/roles/ansible-jenkins/tasks/auth.yml new file mode 100644 index 000000000..fb2281ff4 --- /dev/null +++ b/ansible/roles/ansible-jenkins/tasks/auth.yml @@ -0,0 +1,67 @@ +--- +- name: Check if Jenkins config exists + stat: + path: "{{ jenkins_lib }}/config.xml" + register: jenkins_config_file + +- name: Check if github oauth is already enabled + shell: "grep -q github-oauth {{ jenkins_lib }}/config.xml" + register: github_oauth_enabled + when: jenkins_config_file.stat.exists + failed_when: false + +- name: Remove AuthorizationStrategy$Unsecured + lineinfile: + path: "{{ jenkins_lib }}/config.xml" + regexp: ".*hudson\\.security\\.AuthorizationStrategy\\$Unsecured.*" + state: absent + +- name: Remove SecurityRealm$None + lineinfile: + path: "{{ jenkins_lib }}/config.xml" + regexp: ".*hudson\\.security\\.SecurityRealm\\$None.*" + state: absent + +# Jenkins will automatically update the plugin version, +# remove the ansible blockinfile comments, +# and encrypt github_oauth_secret when the service is restarted +- name: Add/update github-oauth settings + blockinfile: + path: "{{ jenkins_lib }}/config.xml" + insertafter: ".*useSecurity.*" + block: |2 + + + + + + + ktdreyer + alfredodeza + gregmeno + dmick + zmc + andrewschoen + djgalloway + ceph-jenkins + + true + false + false + true + false + true + true + + + + https://github.com + https://api.github.com + {{ github_oauth_client }} + {{ github_oauth_secret }} + read:org,user:email + + when: jenkins_config_file.stat.exists and github_oauth_enabled.rc == 1 + no_log: true + notify: + - restart jenkins diff --git a/ansible/roles/ansible-jenkins/tasks/jenkins.yml b/ansible/roles/ansible-jenkins/tasks/jenkins.yml index d018c12e9..90e18c886 100644 --- a/ansible/roles/ansible-jenkins/tasks/jenkins.yml +++ b/ansible/roles/ansible-jenkins/tasks/jenkins.yml @@ -25,4 +25,11 @@ tags: - plugins +# This should only get run the first time the role is run. +# The variables should be passed as --extra-vars via ansible-playbook command +- include: auth.yml + when: github_oauth_client is defined and github_oauth_secret is defined + tags: + - auth + - include: config.yml