| Total Complexity | 4 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | Common functions for processing Ansible in SSG |
||
| 3 | """ |
||
| 4 | |||
| 5 | from __future__ import absolute_import |
||
| 6 | from __future__ import print_function |
||
| 7 | |||
| 8 | from .constants import ansible_version_requirement_pre_task_name |
||
| 9 | from .constants import min_ansible_version |
||
| 10 | |||
| 11 | |||
| 12 | def add_minimum_version(ansible_src): |
||
| 13 | """ |
||
| 14 | Adds minimum ansible version to an Ansible script |
||
| 15 | """ |
||
| 16 | pre_task = (""" - hosts: all |
||
| 17 | pre_tasks: |
||
| 18 | - name: %s |
||
| 19 | assert: |
||
| 20 | that: "ansible_version.full is version_compare('%s', '>=')" |
||
| 21 | msg: > |
||
| 22 | "You must update Ansible to at least version %s to use this role." |
||
| 23 | """ % (ansible_version_requirement_pre_task_name, |
||
| 24 | min_ansible_version, min_ansible_version)) |
||
| 25 | |||
| 26 | if ' - hosts: all' not in ansible_src: |
||
| 27 | return ansible_src |
||
| 28 | |||
| 29 | if 'pre_task' in ansible_src: |
||
| 30 | if 'ansible_version.full is version_compare' in ansible_src: |
||
| 31 | return ansible_src |
||
| 32 | |||
| 33 | raise ValueError("A pre_task already exists in ansible_src; failing to process: %s" % |
||
| 34 | ansible_src) |
||
| 35 | |||
| 36 | return ansible_src.replace(" - hosts: all", pre_task, 1) |
||
| 37 |