Skip to content

Commit

Permalink
Avoid become_user: jenkins
Browse files Browse the repository at this point in the history
It requires changes to ansible.cfg on Ansible 2.1:
http://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user
  • Loading branch information
solita-timo-mihaljov committed Jul 3, 2016
1 parent 75206ab commit 3689edd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

--------------------------
Version 1.0.2 (2016-07-03)
--------------------------

- Fix issues with ``become_user: jenkins`` on Ansible 2.1.

--------------------------
Version 1.0.1 (2016-07-01)
--------------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/solita.jenkins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ You can install this role and its dependencies with ansible-galaxy_. First add t
# requirements.yml
---
- src: https://github.com/solita/ansible-role-solita.jenkins.git
version: v1.0.1
version: v1.0.2
name: solita.jenkins
.. highlight:: sh
Expand Down
20 changes: 10 additions & 10 deletions tasks/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
scripts: "{{ find_local_scripts.files | map(attribute='path') | map('relpath', solita_jenkins_jobs_dir) | list }}"

- name: Create directories for the Job DSL scripts
become: yes
become_user: jenkins
file:
path: "{{ solita_jenkins_job_dsl_workspace }}/{{ item }}"
state: directory
owner: jenkins
group: jenkins
with_items:
- "{{ scripts | map('dirname') | unique | list }}"

- name: Copy the Job DSL scripts to the job-dsl workspace
become: yes
become_user: jenkins
copy:
src: "{{ solita_jenkins_jobs_dir }}/{{ item }}"
dest: "{{ solita_jenkins_job_dsl_workspace }}/{{ item }}"
owner: jenkins
group: jenkins
with_items: "{{ scripts }}"
register: copy_scripts

Expand All @@ -54,30 +54,30 @@
templates: "{{ find_local_templates.files | map(attribute='path') | map('relpath', solita_jenkins_jobs_dir) | list }}"

- name: Create directories for the Job DSL script templates
become: yes
become_user: jenkins
file:
path: "{{ solita_jenkins_job_dsl_workspace }}/{{ item }}"
state: directory
owner: jenkins
group: jenkins
with_items:
- "{{ templates | map('dirname') | unique | list }}"

- name: Copy the Job DSL script templates to the job-dsl workspace
become: yes
become_user: jenkins
template:
src: "{{ solita_jenkins_jobs_dir }}/{{ item }}"
dest: "{{ solita_jenkins_job_dsl_workspace }}/{{ item | regex_replace('\\.j2$', '') }}"
owner: jenkins
group: jenkins
with_items:
- "{{ templates }}"
register: copy_templates

- name: Remove old Job DSL scripts
become: yes
become_user: jenkins
file:
path: "{{ solita_jenkins_job_dsl_workspace }}/{{ item }}"
state: absent
owner: jenkins
group: jenkins
with_items: "{{ old_scripts | difference(scripts) | difference(templates | map('regex_replace', '\\.j2$', '') | list) }}"
register: remove_old_scripts

Expand Down
14 changes: 8 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
- include: plugins.yml

- name: copy job-dsl-config.xml to destination
become: yes
become_user: jenkins
copy: src={{ role_path }}/files/job-dsl-config.xml dest=/var/lib/jenkins/job-dsl-config.xml
copy:
src: "{{ role_path }}/files/job-dsl-config.xml"
dest: /var/lib/jenkins/job-dsl-config.xml
owner: jenkins
group: jenkins

- name: Create the job-dsl job
shell: java -jar {{ jenkins_jar_location }} -s '{{ solita_jenkins_url }}' create-job job-dsl < '/var/lib/jenkins/job-dsl-config.xml'
shell: java -jar '{{ jenkins_jar_location }}' -s '{{ solita_jenkins_url }}' create-job job-dsl <'/var/lib/jenkins/job-dsl-config.xml'
args:
creates: /var/lib/jenkins/jobs/job-dsl/config.xml
register: create_job_dsl_job

- name: Update the job-dsl job configuration
become: yes
become_user: jenkins
copy:
src: job-dsl-config.xml
dest: /var/lib/jenkins/jobs/job-dsl/config.xml
owner: jenkins
group: jenkins
register: update_job_dsl_job

- name: Reload the job-dsl job
Expand Down

0 comments on commit 3689edd

Please sign in to comment.