GeezerVison is showing github.com — feat(module-api): introduce module_role_path for use within modules · getstackhead/stackhead@f82a8fd
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings Documentation/stackhead-modules/development roles/stackhead_module_api/tasks_internal test/units/plugins/action
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Documentation/stackhead-modules/development/specification.md +6Lines changed: 6 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,12 @@ Make sure the following files exist and the expected behaviour is implemented ac | 37 | 37 | | `tasks/steps/deploy.yml` | The software is configured for the given project. | Project deployment | | 38 | 38 | | `tasks/steps/destroy.yml` | The project configuration for the software is removed. Usually empty as resources created via Terraform are removed automatically. | Project destruction | | 39 | 39 |
| | 40 | +{% hint style="warning" %} | | 41 | +Note that `role_path` will most likely not refer to the path to your role, but to a StackHead role. | | 42 | +StackHead provides the path to your role as `module_role_path`, so you should use that preferably: | | 43 | +`{{ module_role_path | default(role_path) }}` | | 44 | +{% endhint %} | | 45 | + | 40 | 46 | {% hint style="warning" %} | 41 | 47 | Please make sure you use `include_tasks` instead of `import_tasks` in your steps and files included into your steps! | 42 | 48 | {% endhint %} |
Collapse file Copy file name to clipboardExpand all lines: ansible/README.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -15,5 +15,5 @@ Due to the collision of the "ansible" python package and our local "ansible" fol | 15 | 15 | we have to back one directory in order to run tests. | 16 | 16 |
| 17 | 17 | ``` | 18 | | -(cd .. && python -m unittest stackhead/ansible/test/units/plugins/action/module_load_config.py) | | 18 | +(cd .. && python -m unittest stackhead/ansible/test/units/**/**/*.py) | 19 | 19 | ``` |
Collapse file Copy file name to clipboardExpand all lines: ansible/plugins/action/module_load_config.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,8 +39,8 @@ def tf_populate_module_config(self, included_module_config, module_rolepath): | 39 | 39 |
| 40 | 40 | init_path = included_module_config['terraform']['provider']['init'] | 41 | 41 |
| 42 | | - double_quotes = re.compile(r'^{{\s*role_path\s*}}(.*)$') | 43 | | - init_path = double_quotes.sub(module_rolepath + "\\1", init_path) | | 42 | + init_path = re.compile(r'^{{\s*role_path.*\s*}}(.*)$').sub(module_rolepath + "\\1", init_path) | | 43 | + init_path = re.compile(r'^{{\s*module_role_path.*\s*}}(.*)$').sub(module_rolepath + "\\1", init_path) | 44 | 44 |
| 45 | 45 | included_module_config['terraform']['provider']['init'] = init_path | 46 | 46 | return included_module_config | |
Collapse file Copy file name to clipboardExpand all lines: ansible/roles/stackhead_module_api/tasks_internal/execute-module-step.yml +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | vars: | 7 | 7 | module_config: "{{ loaded_config.config_varname }}" | 8 | 8 | - name: "{{ stackhead_action }} {{ module_group }} ({{ module_name }}) configuration" | 9 | | - include_tasks: "{{ lookup('getstackhead.stackhead.role_path', module_name)}}/tasks/steps/{{ stackhead_action }}.yml" | | 9 | + include_tasks: "{{ module_role_path }}/tasks/steps/{{ stackhead_action }}.yml" | | 10 | + vars: | | 11 | + module_role_path: "{{ lookup('getstackhead.stackhead.role_path', module_name) }}" |
Collapse file Copy file name to clipboardExpand all lines: ansible/test/units/plugins/action/module_load_config.py +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,6 +55,26 @@ def test_replacing_role_path_in_terraform_provider_init_path(self): | 55 | 55 | {'foo': 'bar', 'terraform': {'provider': {'init': '{{role_path}}/test'}}}, '/some/path') | 56 | 56 | self.assertEqual({'foo': 'bar', 'terraform': {'provider': {'init': '/some/path/test'}}}, result) | 57 | 57 |
| | 58 | + # module_role_path variable in init | | 59 | + result = subject.tf_populate_module_config( | | 60 | + {'foo': 'bar', 'terraform': {'provider': {'init': '{{ module_role_path }}/test'}}}, '/some/path') | | 61 | + self.assertEqual({'foo': 'bar', 'terraform': {'provider': {'init': '/some/path/test'}}}, result) | | 62 | + | | 63 | + # module_role_path variable in init | | 64 | + result = subject.tf_populate_module_config( | | 65 | + {'foo': 'bar', 'terraform': {'provider': {'init': '{{module_role_path}}/test'}}}, '/some/path') | | 66 | + self.assertEqual({'foo': 'bar', 'terraform': {'provider': {'init': '/some/path/test'}}}, result) | | 67 | + | | 68 | + # module_role_path|default(role_path) variable in init | | 69 | + result = subject.tf_populate_module_config( | | 70 | + {'foo': 'bar', 'terraform': {'provider': {'init': '{{ module_role_path | default(role_path) }}/test'}}}, '/some/path') | | 71 | + self.assertEqual({'foo': 'bar', 'terraform': {'provider': {'init': '/some/path/test'}}}, result) | | 72 | + | | 73 | + # module_role_path|default(role_path) variable in init | | 74 | + result = subject.tf_populate_module_config( | | 75 | + {'foo': 'bar', 'terraform': {'provider': {'init': '{{module_role_path|default(role_path)}}/test'}}}, '/some/path') | | 76 | + self.assertEqual({'foo': 'bar', 'terraform': {'provider': {'init': '/some/path/test'}}}, result) | | 77 | + | 58 | 78 | def test_get_role_path_of_regular_role(self): | 59 | 79 | task = MagicMock(Task) | 60 | 80 | task.async_val = False | |
|