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:
Files identified in the description:
* [`plugins/modules/packaging/os/redhat_subscription.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/packaging/os/redhat_subscription.py)

If these files are incorrect, 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/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @alikins @barnabycourt @kahowell
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Same here with red hat linux 8.5 tested
Files identified in the description:
* [`plugins/modules/redhat_subscription.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/redhat_subscription.py)

If these files are incorrect, 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/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
Hi folks,

since the old PR (https://github.com/ansible/ansible/pull/60266) that was done by @thor was IMHO good, I took the liberty of porting it to this repository (community.general): #5627

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: