|
182 | 182 | - The data will be automatically base64 encoded. |
183 | 183 | - Consider switching to HTTP_POST by using I(CLOUDSTACK_METHOD=post) to increase the HTTP_GET size limit of 2KB to 32 KB. |
184 | 184 | type: str |
| 185 | + user_data_details: |
| 186 | + description: |
| 187 | + - Map used to specify the parameters values for the variables in userdata. |
| 188 | + type: dict |
| 189 | + version_added: 2.5.0 |
| 190 | + user_data_name: |
| 191 | + description: |
| 192 | + - Name of user data to be used. This have precedence over I(user_data). |
| 193 | + type: str |
| 194 | + version_added: 2.5.0 |
185 | 195 | force: |
186 | 196 | description: |
187 | 197 | - Force stop/start the instance if required to apply changes, otherwise a running instance will not be changed. |
@@ -592,6 +602,31 @@ def get_instance(self): |
592 | 602 | break |
593 | 603 | return self.instance |
594 | 604 |
|
| 605 | + def get_user_data_id_by_name(self): |
| 606 | + name = self.module.params.get('user_data_name') |
| 607 | + user_data_id = None |
| 608 | + if name: |
| 609 | + args = { |
| 610 | + 'account': self.get_account(key='name'), |
| 611 | + 'domainid': self.get_domain(key='id'), |
| 612 | + 'projectid': self.get_project(key='id'), |
| 613 | + 'listall': True, |
| 614 | + # name or keyword is documented but not work on cloudstack 4.19 |
| 615 | + # commented util will work it |
| 616 | + # 'name': name, |
| 617 | + } |
| 618 | + |
| 619 | + user_data_list = self.query_api('listUserData', **args) |
| 620 | + if user_data_list: |
| 621 | + for v in user_data_list.get('userdata', []): |
| 622 | + if name.lower() in [v['name'].lower()]: |
| 623 | + user_data_id = v['id'] |
| 624 | + break |
| 625 | + if user_data_id is None: |
| 626 | + self.module.fail_json(msg="User data '%s' not found" % user_data_list) |
| 627 | + |
| 628 | + return user_data_id |
| 629 | + |
595 | 630 | def _get_instance_user_data(self, instance): |
596 | 631 | # Query the user data if we need to |
597 | 632 | if 'userdata' in instance: |
@@ -776,6 +811,8 @@ def deploy_instance(self, start_vm=True): |
776 | 811 | args['networkids'] = networkids |
777 | 812 | args['iptonetworklist'] = self.get_iptonetwork_mappings() |
778 | 813 | args['userdata'] = self.get_user_data() |
| 814 | + args['userdataid'] = self.get_user_data_id_by_name() |
| 815 | + args['userdatadetails'] = self.module.params.get('user_data_details') |
779 | 816 | args['keyboard'] = self.module.params.get('keyboard') |
780 | 817 | args['ipaddress'] = self.module.params.get('ip_address') |
781 | 818 | args['ip6address'] = self.module.params.get('ip6_address') |
@@ -815,12 +852,22 @@ def update_instance(self, instance, start_vm=True): |
815 | 852 | args_service_offering['serviceofferingid'] = self.get_service_offering_id() |
816 | 853 | service_offering_changed = self.has_changed(args_service_offering, instance) |
817 | 854 |
|
818 | | - # Instance data |
819 | | - args_instance_update = { |
820 | | - 'id': instance['id'], |
821 | | - 'userdata': self.get_user_data(), |
822 | | - } |
823 | | - instance['userdata'] = self._get_instance_user_data(instance) |
| 855 | + # Instance UserData |
| 856 | + if self.module.params.get('user_data_name') is not None: |
| 857 | + args_instance_update = { |
| 858 | + 'id': instance['id'], |
| 859 | + 'userdataid': self.get_user_data_id_by_name() |
| 860 | + } |
| 861 | + else: |
| 862 | + args_instance_update = { |
| 863 | + 'id': instance['id'], |
| 864 | + 'userdata': self.get_user_data() |
| 865 | + } |
| 866 | + instance['userdata'] = self._get_instance_user_data(instance) |
| 867 | + |
| 868 | + if self.module.params.get('user_data_details'): |
| 869 | + args_instance_update['userdatadetails'] = self.module.params.get('user_data_details') |
| 870 | + |
824 | 871 | args_instance_update['ostypeid'] = self.get_os_type(key='id') |
825 | 872 | if self.module.params.get('group'): |
826 | 873 | args_instance_update['group'] = self.module.params.get('group') |
@@ -1105,6 +1152,8 @@ def main(): |
1105 | 1152 | account=dict(), |
1106 | 1153 | project=dict(), |
1107 | 1154 | user_data=dict(), |
| 1155 | + user_data_name=dict(), |
| 1156 | + user_data_details=dict(type='dict'), |
1108 | 1157 | zone=dict(required=True), |
1109 | 1158 | ssh_key=dict(no_log=False), |
1110 | 1159 | force=dict(type='bool', default=False), |
|
0 commit comments