Repository: ansible-collections/community.general

Issue:
redhat_subscription: consumer_name is ignored
### Summary

When using consumer_name to override name for foreman registration it is ignored during deployment  redhat_subscription task: example below
 
 this was reported in 2018 here:  https://github.com/ansible/ansible/issues/50502 but looks to be not fixed
 
example:
  redhat_subscription:
    org_id: "{{ foreman_default_organisation }}"
    activationkey: "{{ foreman_activation_key }}"
    consumer_name: "{{ foreman_register_consumer_hostname }}"
    force_register: "{{ foreman_register_force | default('no') | bool }}"
    auto_attach: yes

### Issue Type

Bug Report

### Component Name

redhat_subscription

### Ansible Version

```console (paste below)
$ ansible --version
2.9.23
```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general
community.general:3.7.0'
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
 redhat_subscription:
    org_id: "{{ foreman_default_organisation }}"
    activationkey: "{{ foreman_activation_key }}"
    consumer_name: "{{ foreman_register_consumer_hostname }}"
    force_register: "{{ foreman_register_force | default('no') | bool }}"
    auto_attach: yes
```


### OS / Environment

CentOS 7 / OSX / Molecule testing

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
run task - overriding consumer_name variable with somthing different to hostname
 redhat_subscription:
    org_id: "{{ foreman_default_organisation }}"
    activationkey: "{{ foreman_activation_key }}"
    consumer_name: "{{ foreman_register_consumer_hostname }}"
    force_register: "{{ foreman_register_force | default('no') | bool }}"
    auto_attach: yes
```


### Expected Results

name in foreman should be different to hostname on server if consumer_name is overriden

### Actual Results

```console (paste below)
hostname stays the same
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:

Resolving patch:
diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py
--- a/plugins/modules/redhat_subscription.py
+++ b/plugins/modules/redhat_subscription.py
@@ -411,23 +411,28 @@ def register(self, username, password, auto_attach, activationkey, org_id,
         if org_id:
             args.extend(['--org', org_id])
 
+        if auto_attach:
+            args.append('--auto-attach')
+
+        if consumer_type:
+            args.extend(['--type', consumer_type])
+
+        if consumer_name:
+            args.extend(['--name', consumer_name])
+
+        if consumer_id:
+            args.extend(['--consumerid', consumer_id])
+
+        if environment:
+            args.extend(['--environment', environment])
+
         if activationkey:
             args.extend(['--activationkey', activationkey])
         else:
-            if auto_attach:
-                args.append('--auto-attach')
             if username:
                 args.extend(['--username', username])
             if password:
                 args.extend(['--password', password])
-            if consumer_type:
-                args.extend(['--type', consumer_type])
-            if consumer_name:
-                args.extend(['--name', consumer_name])
-            if consumer_id:
-                args.extend(['--consumerid', consumer_id])
-            if environment:
-                args.extend(['--environment', environment])
 
         if release:
             args.extend(['--release', release])


Test patch: