Repository: ansible/ansible

Issue:
azure_rm_loadbalancer does not set tags
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
azure_rm_loadbalancer 

##### ANSIBLE VERSION
```
ansible 2.6.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
```

##### CONFIGURATION
```
DEFAULT_TIMEOUT(/etc/ansible/ansible.cfg) = 120
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False
```

##### OS / ENVIRONMENT
N/A

##### SUMMARY
When creating a loadbalancer with tags, the tags do not show up in azure.

##### STEPS TO REPRODUCE
Create a load balancer with tags:
```yaml
    - name: Create loadbalancer
      azure_rm_loadbalancer:
        name: "mylb"
...
        tags:
          "mytag": "myvalue"
```

##### EXPECTED RESULTS
The tag has been added to the load balancer

##### ACTUAL RESULTS
The tag is not there

##### Patch
The following patch fixes my issue; not sure it will actually honor the update_tags parameter.

```
--- a/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py
@@ -620,7 +620,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase):

     def exec_module(self, **kwargs):
         """Main module execution method"""
-        for key in self.module_args.keys():
+        for key in self.module_args.keys() + ['tags']:
             setattr(self, key, kwargs[key])

         changed = False
@@ -761,6 +761,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
             param = self.network_models.LoadBalancer(
                 sku=self.network_models.LoadBalancerSku(self.sku) if self.sku else None,
                 location=self.location,
+                tags=self.tags,
                 frontend_ip_configurations=frontend_ip_configurations_param,
                 backend_address_pools=backend_address_pools_param,
                 probes=probes_param,
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @haroldwongms @nitzmahone @trstringer @tstringer @xscript @yuwzho @zikalino
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
+label easyfix

Add a label to welcome contributor to fix this, before I have bandwidth.
@yuwzho Are you requesting me to send a pull request for this fix?
@yuwzho I meet the same error when used azure_rm_loadbalancer to create a loadbalancer with tags, the tag will not create, it need to be fixed. Thanks !

@vogon1 If you are interested in it hhhh 😄 
@yuwzho I created a pull request, you will see the name SietseVisser - that is me as well, it is my job account.

Resolving patch:
diff --git a/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py b/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py
--- a/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py
@@ -610,6 +610,7 @@ def __init__(self):
         self.natpool_frontend_port_end = None
         self.natpool_backend_port = None
         self.natpool_protocol = None
+        self.tags = None
 
         self.results = dict(changed=False, state=dict())
 
@@ -620,7 +621,7 @@ def __init__(self):
 
     def exec_module(self, **kwargs):
         """Main module execution method"""
-        for key in self.module_args.keys():
+        for key in list(self.module_args.keys()) + ['tags']:
             setattr(self, key, kwargs[key])
 
         changed = False
@@ -685,6 +686,13 @@ def exec_module(self, **kwargs):
             changed = True
 
         self.results['state'] = load_balancer_to_dict(load_balancer)
+        if 'tags' in self.results['state']:
+            update_tags, self.results['state']['tags'] = self.update_tags(self.results['state']['tags'])
+            if update_tags:
+                changed = True
+        else:
+            if self.tags:
+                changed = True
         self.results['changed'] = changed
 
         if self.state == 'present' and changed:
@@ -761,6 +769,7 @@ def exec_module(self, **kwargs):
             param = self.network_models.LoadBalancer(
                 sku=self.network_models.LoadBalancerSku(self.sku) if self.sku else None,
                 location=self.location,
+                tags=self.tags,
                 frontend_ip_configurations=frontend_ip_configurations_param,
                 backend_address_pools=backend_address_pools_param,
                 probes=probes_param,


Test patch: