mirror of
https://github.com/ansible/awx.git
synced 2026-03-03 09:48:51 -03:30
add update to tower project
This commit is contained in:
@@ -91,6 +91,8 @@ options:
|
|||||||
timeout:
|
timeout:
|
||||||
description:
|
description:
|
||||||
- The amount of time (in seconds) to run before the SCM Update is canceled. A value of 0 means no timeout.
|
- The amount of time (in seconds) to run before the SCM Update is canceled. A value of 0 means no timeout.
|
||||||
|
- If waiting for the project to update this will abort after this
|
||||||
|
amount of seconds
|
||||||
default: 0
|
default: 0
|
||||||
type: int
|
type: int
|
||||||
aliases:
|
aliases:
|
||||||
@@ -133,6 +135,19 @@ options:
|
|||||||
- list of notifications to send on error
|
- list of notifications to send on error
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
|
update_project:
|
||||||
|
description:
|
||||||
|
- Force project to update after changes.
|
||||||
|
- Used in conjunction with wait, interval, and timeout.
|
||||||
|
default: False
|
||||||
|
type: bool
|
||||||
|
interval:
|
||||||
|
description:
|
||||||
|
- The interval to request an update from Tower.
|
||||||
|
- Requires wait.
|
||||||
|
required: False
|
||||||
|
default: 1
|
||||||
|
type: float
|
||||||
extends_documentation_fragment: awx.awx.auth
|
extends_documentation_fragment: awx.awx.auth
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@@ -177,6 +192,25 @@ def wait_for_project_update(module, last_request):
|
|||||||
|
|
||||||
if result['status'] != 'successful':
|
if result['status'] != 'successful':
|
||||||
module.fail_json(msg="Project update failed")
|
module.fail_json(msg="Project update failed")
|
||||||
|
elif update_project:
|
||||||
|
result = module.post_endpoint(last_request['related']['update'])
|
||||||
|
|
||||||
|
if result['status_code'] != 202:
|
||||||
|
module.fail_json(msg="Failed to update project, see response for details", response=result)
|
||||||
|
|
||||||
|
if not wait:
|
||||||
|
module.exit_json(**module.json_output)
|
||||||
|
|
||||||
|
# Grab our start time to compare against for the timeout
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
|
# Invoke wait function
|
||||||
|
module.wait_on_url(
|
||||||
|
url=result['json']['url'],
|
||||||
|
object_name=module.get_item_name(last_request),
|
||||||
|
object_type='Project Update',
|
||||||
|
timeout=timeout, interval=interval
|
||||||
|
)
|
||||||
|
|
||||||
module.exit_json(**module.json_output)
|
module.exit_json(**module.json_output)
|
||||||
|
|
||||||
@@ -205,6 +239,8 @@ def main():
|
|||||||
notification_templates_error=dict(type="list", elements='str'),
|
notification_templates_error=dict(type="list", elements='str'),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
wait=dict(type='bool', default=True),
|
wait=dict(type='bool', default=True),
|
||||||
|
update_project=dict(default=False, type='bool'),
|
||||||
|
interval=dict(default=1.0, type='float'),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a module for ourselves
|
# Create a module for ourselves
|
||||||
@@ -231,6 +267,8 @@ def main():
|
|||||||
organization = module.params.get('organization')
|
organization = module.params.get('organization')
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
wait = module.params.get('wait')
|
wait = module.params.get('wait')
|
||||||
|
update_project = module.params.get('update_project')
|
||||||
|
interval = module.params.get('interval')
|
||||||
|
|
||||||
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
||||||
lookup_data = {}
|
lookup_data = {}
|
||||||
@@ -300,7 +338,7 @@ def main():
|
|||||||
# If we are doing a not manual project, register our on_change method
|
# If we are doing a not manual project, register our on_change method
|
||||||
# An on_change function, if registered, will fire after an post_endpoint or update_if_needed completes successfully
|
# An on_change function, if registered, will fire after an post_endpoint or update_if_needed completes successfully
|
||||||
on_change = None
|
on_change = None
|
||||||
if wait and scm_type != '':
|
if wait and scm_type != '' or update_project and scm_type != '':
|
||||||
on_change = wait_for_project_update
|
on_change = wait_for_project_update
|
||||||
|
|
||||||
# If the state was present and we can let the module build or update the existing project, this will return on its own
|
# If the state was present and we can let the module build or update the existing project, this will return on its own
|
||||||
|
|||||||
@@ -126,9 +126,6 @@ def main():
|
|||||||
# Grab our start time to compare against for the timeout
|
# Grab our start time to compare against for the timeout
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
if not wait:
|
|
||||||
module.exit_json(**module.json_output)
|
|
||||||
|
|
||||||
# Invoke wait function
|
# Invoke wait function
|
||||||
module.wait_on_url(
|
module.wait_on_url(
|
||||||
url=result['json']['url'],
|
url=result['json']['url'],
|
||||||
|
|||||||
@@ -138,6 +138,29 @@
|
|||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
|
|
||||||
|
- name: Update a git project, update the project and wait.
|
||||||
|
tower_project:
|
||||||
|
name: "{{ project_name3 }}"
|
||||||
|
organization: Default
|
||||||
|
scm_type: git
|
||||||
|
scm_branch: empty_branch
|
||||||
|
scm_url: https://github.com/ansible/test-playbooks
|
||||||
|
allow_override: true
|
||||||
|
wait: true
|
||||||
|
update_project: true
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Update a git project, update the project without waiting.
|
||||||
|
tower_project:
|
||||||
|
name: "{{ project_name3 }}"
|
||||||
|
organization: Default
|
||||||
|
scm_type: git
|
||||||
|
scm_branch: empty_branch
|
||||||
|
scm_url: https://github.com/ansible/test-playbooks
|
||||||
|
wait: false
|
||||||
|
update_project: true
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Create a job template that overrides the project scm_branch
|
- name: Create a job template that overrides the project scm_branch
|
||||||
tower_job_template:
|
tower_job_template:
|
||||||
name: "{{ jt1 }}"
|
name: "{{ jt1 }}"
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
- name: Run Integration Test
|
||||||
|
hosts: localhost
|
||||||
|
connection: local
|
||||||
|
gather_facts: False
|
||||||
|
environment:
|
||||||
|
TOWER_HOST: https://ansible-tower-web-svc-tower.apps-crc.testing
|
||||||
|
TOWER_USERNAME: admin
|
||||||
|
TOWER_PASSWORD: password
|
||||||
|
TOWER_VERIFY_SSL: False
|
||||||
|
collections:
|
||||||
|
- awx.awx
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: Update a git project, update the project and wait.
|
||||||
|
tower_project:
|
||||||
|
name: abcd
|
||||||
|
organization: Default
|
||||||
|
scm_type: git
|
||||||
|
scm_branch: empty_branch
|
||||||
|
scm_url: https://github.com/ansible/test-playbooks
|
||||||
|
allow_override: true
|
||||||
|
wait: true
|
||||||
|
update_project: true
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Sleep for 300 seconds and continue with play
|
||||||
|
wait_for:
|
||||||
|
timeout: 15
|
||||||
|
|
||||||
|
- name: Update a git project, update the project without waiting.
|
||||||
|
tower_project:
|
||||||
|
name: abcd
|
||||||
|
organization: Default
|
||||||
|
scm_type: git
|
||||||
|
scm_branch: empty_branch
|
||||||
|
scm_url: https://github.com/ansible/test-playbooks
|
||||||
|
wait: false
|
||||||
|
update_project: true
|
||||||
|
register: result
|
||||||
Reference in New Issue
Block a user