Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple users, filesystem definitions, etc. can't be done #344

Open
Ramkumarselvam1 opened this issue Feb 1, 2024 · 4 comments
Open

multiple users, filesystem definitions, etc. can't be done #344

Ramkumarselvam1 opened this issue Feb 1, 2024 · 4 comments

Comments

@Ramkumarselvam1
Copy link

Unable to create multiple users or filesystem due to module dict can only contain one of each key,

From create blue print.py:-
line no: 177
toml_data["customizations"]: dict = {}
for key, customization in module.params["customizations"].items():
if isinstance(customization, str):
toml_data["customizations"][key]: str = customization
continue
# TODO since the module dict can only contain one of each key,
# multiple users, filesystem definitions, etc. can't be done yet
double_square_brackets: list = ["user", "filesystem", "sshkey", "directories", "files"]
if key in double_square_brackets:
toml_data["customizations"][key]: list = []
toml_data["customizations"][key].append(customization)
else:
toml_data["customizations"][key]: dict = customization
try:
with open(module.params["dest"], "w") as fd:
weldr.toml.dump(toml_data, fd)
except Exception as e:
module.fail_json(msg=f'Failed to write to file: {module.params["dest"]}', error=e)
module.exit_json(msg=f'Blueprint file written to location: {module.params["dest"]}', changed=True, current_version=blueprint_version)

@chadmf
Copy link
Collaborator

chadmf commented Feb 9, 2024

can you please add how to replicate the issue?

@Ramkumarselvam1
Copy link
Author

When u add user under customization only the last user been populated in the blueprint.

eg
[customization]
User:
Name:ram
User:
Name:kumar

it prints only kumar in blueprint

@Ramkumarselvam1
Copy link
Author

EG:- [root@node-1 library]# cat ../defaults/main.yml

builder_blueprint_name: test_blueprint
builder_blueprint_src_path: /tmp/blueprint.toml
builder_blueprint_distro_lower: "{{ 'rhel' if ansible_distribution == 'RedHat' else ansible_distribution | lower }}"
builder_blueprint_ref: "{{ builder_blueprint_distro_lower }}/{{ hostvars[inventory_hostname].ansible_distribution_major_version }}/x86_64/{{ 'iot' if ansible_distribution == 'Fedora' else 'edge' }}" # yamllint disable-line rule:line-length
builder_compose_type: edge-installer
builder_pub_key_path: "~/.ssh/id_rsa.pub"
builder_password: openshift
builder_enforce_auth: true
builder_compose_pkgs:

  • "vim-enhanced"
  • "git"
  • "ansible-core"
    builder_compose_customizations:

user:
name: "core"
description: "test user"
password: "{{ builder_password if builder_password is defined else '' }}"
key: "{{ builder_pub_key if builder_pub_key is defined else (lookup('file', builder_pub_key_path, errors='warn') if builder_pub_key_path is defined else '') }}" # noqa yaml[line-length]
groups:
- "users"
- "wheel"
user:
name: "core1"
description: "test user2"
password: "{{ builder_password if builder_password is defined else '' }}"
key: "{{ builder_pub_key if builder_pub_key is defined else (lookup('file', builder_pub_key_path, errors='warn') if builder_pub_key_path is defined else '') }}" # noqa yaml[line-length]
groups:
- "users"
- "wheel"
builder_image_storage_threshold: 3 # percentage
builder_image_storage_cleared: false
builder_system_ipv4: "{{ ansible_default_ipv4.address }}"
builder_request_timeout: 120
builder_error_log_length: 5

Wen I present this value in the role builder on default *yml file, after the blue print is created the number of users produced is just one with latest. Only below values are present.
user:
name: "core1"
description: "test user2"
password: "{{ builder_password if builder_password is defined else '' }}"
key: "{{ builder_pub_key if builder_pub_key is defined else (lookup('file', builder_pub_key_path, errors='warn') if builder_pub_key_path is defined else '') }}" # noqa yaml[line-length]
groups:
- "users"
- "wheel"

irrespective of number of users we provided in the customization we get only last items, you can validate by reviewing under the plugins to create_blueprint on line no:182

    # TODO since the module dict can only contain one of each key,
    # multiple users, filesystem definitions, etc. can't be done yet
    double_square_brackets: list = ["user", "filesystem", "sshkey"]
    if key in double_square_brackets:
        toml_data["customizations"][key]: list = []
        toml_data["customizations"][key].append(customization)
    else:
        toml_data["customizations"][key]: dict = customization

try:
    with open(module.params["dest"], "w") as fd:
        weldr.toml.dump(toml_data, fd)
except Exception as e:
    module.fail_json(msg=f'Failed to write to file: {module.params["dest"]}', error=e)

module.exit_json(msg=f'Blueprint file written to location: {module.params["dest"]}', changed=True, current_version=blueprint_version)

@lucamaf
Copy link

lucamaf commented Jul 24, 2024

any update on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants