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

inventory variables: multiple spaces collapsed to single spaces #849

Closed
amunro-tsl opened this issue Jun 28, 2024 · 3 comments · Fixed by #850
Closed

inventory variables: multiple spaces collapsed to single spaces #849

amunro-tsl opened this issue Jun 28, 2024 · 3 comments · Fixed by #850
Labels
bug Something isn't working

Comments

@amunro-tsl
Copy link

amunro-tsl commented Jun 28, 2024

Summary

When using controller_inventories variables with a config block with multiple spaces, the spaces are collapsed to single spaces.

Issue Type

  • Bug Report

Ansible, Collection, Controller details

ansible --version
core 2.15.11

ansible-galaxy collection list
infra.controller_configuration:2.8.1

Controller version: installed from 2.4.7 bundle.
  • ansible installation method: one of source, pip, OS package, EE

OS / ENVIRONMENT

Desired Behavior

Actual Behavior

Please give some details of what is actually happening.
Include a [minimum complete verifiable example] with:

  • playbook / task
  • configuration file / list
  • error
controller_inventories:
  - name: helix_test
    organization: Infrastructure_Services
    variables:
      ansible_connection: ssh
      ansible_user: ansible
      ansible_become_user: root
      managed_ansible: |
        #######################################
        ##            DO NOT EDIT!           ##
        ## This file is managed by Ansible   ##
        ##            DO NOT EDIT!           ##
        #######################################
      motd_template: doublehelix

This turns up in the inventory in the gui as:

managed_ansible: |
  #######################################
  ##DO NOT EDIT!##
  ## This file is managed by Ansible##
  ##DO NOT EDIT!##
  #######################################

I have checked the source for tabs or any odd control characters; its just spaces and ASCII codes.

$ cat a
---
controller_inventories:
  - name: helix_test
    variables:
      managed_ansible: |
        #######################################
        ##            DO NOT EDIT!           ##
        ## This file is managed by Ansible   ##
        ##            DO NOT EDIT!           ##
        #######################################

$ od -a a
0000000   -   -   -  nl   c   o   n   t   r   o   l   l   e   r   _   i
0000020   n   v   e   n   t   o   r   i   e   s   :  nl  sp  sp   -  sp
0000040   n   a   m   e   :  sp   h   e   l   i   x   _   t   e   s   t
0000060  nl  sp  sp  sp  sp   v   a   r   i   a   b   l   e   s   :  nl
0000100  sp  sp  sp  sp  sp  sp   m   a   n   a   g   e   d   _   a   n
0000120   s   i   b   l   e   :  sp   |  nl  sp  sp  sp  sp  sp  sp  sp
0000140  sp   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #
0000160   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #
0000200   #   #   #   #   #   #   #   #  nl  sp  sp  sp  sp  sp  sp  sp
0000220  sp   #   #  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp   D
0000240   O  sp   N   O   T  sp   E   D   I   T   !  sp  sp  sp  sp  sp
0000260  sp  sp  sp  sp  sp  sp   #   #  nl  sp  sp  sp  sp  sp  sp  sp
0000300  sp   #   #  sp   T   h   i   s  sp   f   i   l   e  sp   i   s
0000320  sp   m   a   n   a   g   e   d  sp   b   y  sp   A   n   s   i
0000340   b   l   e  sp  sp  sp   #   #  nl  sp  sp  sp  sp  sp  sp  sp
0000360  sp   #   #  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp   D
0000400   O  sp   N   O   T  sp   E   D   I   T   !  sp  sp  sp  sp  sp
0000420  sp  sp  sp  sp  sp  sp   #   #  nl  sp  sp  sp  sp  sp  sp  sp
0000440  sp   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #
0000460   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #
0000500   #   #   #   #   #   #   #   #  nl
0000511

STEPS TO REPRODUCE

$ cat controller_automator_dev.yml 
---
- name: Add objects to Automation Controller
  hosts: controller_dev
  connection: local
    roles:
    - infra.controller_configuration.dispatch

$ cat base_config/host_vars/controller_dev/inventories.yml 
---
controller_inventories:
  - name: helix_test
    organization: Demo
    variables:
      managed_ansible: |
        #######################################
        ##            DO NOT EDIT!           ##
        ## This file is managed by Ansible   ##
        ##            DO NOT EDIT!           ##
        #######################################
      ansible_connection: ssh

$ ansible-playbook controller_automator_dev.yml -i base_config
@amunro-tsl amunro-tsl added bug Something isn't working new New issue, this should be removed once reviewed labels Jun 28, 2024
@Tompage1994
Copy link
Collaborator

Hi @amunro-tsl thanks for this bug report.

I've found the offending line:

https://github.com/redhat-cop/controller_configuration/blob/a2b7b51e97b279782f97a76f21871e5e82742ce3/roles/inventories/tasks/main.yml#L11

I'll do some investigation why the regex_replace is needed there and see if I can find a fix or workaround for this

@Tompage1994
Copy link
Collaborator

This section of the readme explains why we strip spaces. I'll see if I can do something more clever with this

Formating Variables
Variables can use a standard Jinja templating format to describe the resource.

Example:

{{ variable }}
Because of this it is difficult to provide controller with the required format for these fields.

The workaround is to use the following format:

{  { variable }}
The role will strip the double space between the curly bracket in order to provide controller with the correct format for the Variables.

@Tompage1994 Tompage1994 removed the new New issue, this should be removed once reviewed label Jul 1, 2024
@amunro-tsl
Copy link
Author

Thanks @Tompage1994 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants