theforeman / foreman-ansible-modules

Ansible modules for interacting with the Foreman API and various plugin APIs such as Katello
GNU General Public License v3.0
147 stars 163 forks source link

Organization Can't Have a Comma #1293

Open carl-schelin opened 2 years ago

carl-schelin commented 2 years ago
SUMMARY

When I used the organization option to create a new organization, I used my personal company, 'Hobgoblin Consulting Services, LLC'. When I tried to use this in further plays, it returned an error, "Can't find Hobgoblin Consulting Services" without the trailing ', LLC'. Recreating the organization without the ", LLC" worked.

ISSUE TYPE
ANSIBLE VERSION
$ ansible --version
ansible 2.9.25
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/unixsvc/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Mar 19 2021, 05:13:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
COLLECTION VERSION
$ ansible-galaxy collection list
usage: ansible-galaxy collection [-h] COLLECTION_ACTION ...
ansible-galaxy collection: error: argument COLLECTION_ACTION: invalid choice: 'list' (choose from 'init', 'build', 'publish', 'install')
KATELLO/FOREMAN VERSION
$ rpm -q tfm-rubygem-katello foreman
tfm-rubygem-katello-3.18.5-1.el7.noarch
foreman-2.3.5-1.el7.noarch
STEPS TO REPRODUCE

katello_password: [password to new server] katello_url: [url to new server] katello_organization: "Hobgoblin Consulting Services, LLC"

---
- name: Configure Organization
  theforeman.foreman.organization:
    username: admin
    password: "{{ katello_password }}"
    server_url: "{{ katello_url }}"
    name: "{{ katello_organization }}"
    state: present

- name: Configure locations
  theforeman.foreman.location:
    username: admin
    password: "{{ katello_password }}"
    server_url: "{{ katello_url }}"
    organizations: "{{ katello_organization }}"
    name: "{{ item }}"
    state: present
  with_items:
    - Boulder
    - Cabo
    - Tatooine
    - Longmont
EXPECTED RESULTS

All subsequent tasks are able to use the full Organization Name.

ACTUAL RESULTS
$ ansible-playbook -i /usr/local/admin/etc/hosts --ask-vault-pass -e pattern='lnmt1cuomkat1' install_katello.yaml
Vault password:

PLAY [lnmt1cuomkat1] **************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************************
ok: [lnmt1cuomkat1]

TASK [configure : Configure Organization] *****************************************************************************************************************
ok: [lnmt1cuomkat1]

TASK [configure : Configure Dallas location] **************************************************************************************************************
failed: [lnmt1cuomkat1] (item=Boulder) => {"ansible_loop_var": "item", "changed": false, "item": "Boulder", "msg": "Found no results while searching for organizations with name=\"Hobgoblin Consulting Services\""}
failed: [lnmt1cuomkat1] (item=Cabo) => {"ansible_loop_var": "item", "changed": false, "item": "Cabo", "msg": "Found no results while searching for organizations with name=\"Hobgoblin Consulting Services\""}
failed: [lnmt1cuomkat1] (item=Tatooine) => {"ansible_loop_var": "item", "changed": false, "item": "Tatooine", "msg": "Found no results while searching for organizations with name=\"Hobgoblin Consulting Services\""}
failed: [lnmt1cuomkat1] (item=Longmont) => {"ansible_loop_var": "item", "changed": false, "item": "Longmont", "msg": "Found no results while searching for organizations with name=\"Hobgoblin Consulting Services\""}

PLAY RECAP ************************************************************************************************************************************************
lnmt1cuomkat1              : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
evgeni commented 2 years ago

Does that also happen when you write

organizations:
  - "{{ katello_organization }}"

As organizations of a location are a list, and it might split on the comma.

carl-schelin commented 2 years ago

I haven't tried that but it's a good question. I'll give it a shot.

Yep, that worked. I was copy/pasting blocks of the variables between playbooks and needed to add 's' to 'organization' for this one to work.

Thanks!

evgeni commented 2 years ago

Yeah, some entities in Foreman can belong to multiple Organizations (and Locations), and some can't. That's why some modules expect a list (and have an s), and some not.

And then Ansible tries to be helpful when you pass a string to a parameter that expects a list 🙄

mdellweg commented 2 years ago

This sounds to me like there is nothing we can do about it, but documenting it.