use insights etag as a cache

* During insights project updates, if the etag from insights matches the
last etag (scm_revision) then don't get all the maintenance playbooks.
Otherwise, get all the maintenance playbooks and update scm_revision
with the etag.
This commit is contained in:
Chris Meyers
2017-05-30 18:30:13 -04:00
parent b049d624ad
commit 0c034f29af
2 changed files with 45 additions and 35 deletions

View File

@@ -1291,7 +1291,8 @@ class RunProjectUpdate(BaseTask):
'scm_clean': project_update.scm_clean, 'scm_clean': project_update.scm_clean,
'scm_delete_on_update': project_update.scm_delete_on_update if project_update.job_type == 'check' else False, 'scm_delete_on_update': project_update.scm_delete_on_update if project_update.job_type == 'check' else False,
'scm_full_checkout': True if project_update.job_type == 'run' else False, 'scm_full_checkout': True if project_update.job_type == 'run' else False,
'scm_revision_output': self.revision_path 'scm_revision_output': self.revision_path,
'scm_revision': project_update.project.scm_revision,
}) })
args.extend(['-e', json.dumps(extra_vars)]) args.extend(['-e', json.dumps(extra_vars)])
args.append('project_update.yml') args.append('project_update.yml')

View File

@@ -10,6 +10,7 @@
# scm_username: username (only for svn) # scm_username: username (only for svn)
# scm_password: password (only for svn) # scm_password: password (only for svn)
# scm_accept_hostkey: true/false (only for git) # scm_accept_hostkey: true/false (only for git)
# scm_revision: current revision in tower
- hosts: all - hosts: all
connection: local connection: local
@@ -105,20 +106,26 @@
scm_version: "{{ scm_result['after'] }}" scm_version: "{{ scm_result['after'] }}"
when: "'after' in scm_result" when: "'after' in scm_result"
- block:
- name: update project using insights - name: update project using insights
uri: uri:
url: "{{insights_url}}/r/insights/v1/maintenance?ansible=true" url: "{{insights_url}}/r/insights/v1/maintenance?ansible=true"
user: "{{scm_username}}" user: "{{scm_username}}"
password: "{{scm_password}}" password: "{{scm_password}}"
force_basic_auth: yes force_basic_auth: yes
when: scm_type == 'insights'
register: insights_output register: insights_output
- name: Set the insights cache version
set_fact:
scm_version: "{{ insights_output.etag|default(scm_revision)|regex_replace('\"(.*)\"$', '\\1') }}"
when: scm_type == 'insights'
- block:
- name: Ensure the project directory is present - name: Ensure the project directory is present
file: file:
dest: "{{project_path|quote}}" dest: "{{project_path|quote}}"
state: directory state: directory
when: scm_type == 'insights'
- name: Fetch Insights Playbook With Name - name: Fetch Insights Playbook With Name
get_url: get_url:
@@ -128,7 +135,7 @@
url_password: "{{scm_password}}" url_password: "{{scm_password}}"
force_basic_auth: yes force_basic_auth: yes
force: yes force: yes
when: scm_type == 'insights' and item.name != None and item.name != "" when: item.name != None and item.name != ""
with_items: "{{ insights_output.json|default([]) }}" with_items: "{{ insights_output.json|default([]) }}"
failed_when: false failed_when: false
@@ -140,10 +147,12 @@
url_password: "{{scm_password}}" url_password: "{{scm_password}}"
force_basic_auth: yes force_basic_auth: yes
force: yes force: yes
when: scm_type == 'insights' and (item.name == None or item.name == "") when: (item.name == None or item.name == "")
with_items: "{{ insights_output.json|default([]) }}" with_items: "{{ insights_output.json|default([]) }}"
failed_when: false failed_when: false
when: scm_type == 'insights' and scm_version != scm_revision
- name: detect requirements.yml - name: detect requirements.yml
stat: path={{project_path|quote}}/roles/requirements.yml stat: path={{project_path|quote}}/roles/requirements.yml
register: doesRequirementsExist register: doesRequirementsExist