Skip to content

Support templating in ansible_user #344

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jovial
Copy link

@jovial jovial commented Mar 25, 2022

SUMMARY

Before this change it is not possible to use templating for the ansible_user e.g:

  ansible_user: "{{ some_variable }}"

The error you see looks like:

Unexpected remote arg: }}@10.0.0.97:/tmp/ansible.lq33g1agrally-results/\nrsync error: syntax or usage error (code 1) at main.c(1354) [sender=3.1.3]\n"

The module arguments look like:

        "module_args": {                                                                                                                                                      
            "_local_rsync_password": null,                                                                                                                                    
            "_local_rsync_path": "rsync",                                                                                                                                     
            "_substitute_controller": false,                                                                                                                                  
            "archive": false,                                                                                                                                                 
            "checksum": false,                                                                                                                                                
            "compress": true,                                                                                                                                                 
            "copy_links": false,                                                                                                                                              
            "delay_updates": true,                                                                                                                                            
            "delete": false,                                                                                                                                                  
            "dest": "/stack/tempest-artifacts",                                                                                                                               
            "dest_port": null,                                                                                                                                                
            "dirs": false,                                                                                                                                                    
            "existing_only": false,                                                                                                                                           
            "group": null,                                                                                                                                                    
            "link_dest": null,                                                                                                                                                
            "links": null,                                                                                                                                                    
            "mode": "pull",                                                                                                                                                   
            "owner": null,                                                                                                                                                    
            "partial": false,                                                                                                                                                 
            "perms": null,                                                                                                                                                    
            "private_key": null,                                                                                                                                              
            "recursive": true,                                                                                                                                                
            "rsync_opts": [],                                                                                                                                                 
            "rsync_path": null,                                                                                                                                               
            "rsync_timeout": 0,                                                                                                                                               
            "set_remote_user": true,                                                                                                                                          
            "src": "{{ kayobe_ansible_user }}@10.0.0.97:/tmp/ansible.lq33g1agrally-results/",                                                                                 
            "ssh_args": "-C -o ControlMaster=auto -o ControlPersist=60s",                                                                                                     
            "ssh_connection_multiplexing": false,                                                                                                                             
            "times": null,                                                                                                                                                    
            "verify_host": false                                                                                                                                              
        } 

In this case I'm using:

ansible_user: "{{ kayobe_ansible_user }}"
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

synchronize

ADDITIONAL INFORMATION

Before this change it is not possible to use templating for the ansible_user e.g:

  ansible_user: "{{ some_variable }}"
@@ -347,6 +347,7 @@ def run(self, tmp=None, task_vars=None):

else:
user = task_vars.get('ansible_user') or self._play_context.remote_user
user = self._templar.template(user)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the vars were always the wrong thing to get, the correct info should be from the connection itself using get_option

Copy link
Author

@jovial jovial May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good suggestion. Would we need to parse ssh_args to get the user? Or is that exposed as an option? Do we need to consider other connection plugins other than ssh?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @bcoca @jovial - this conversation is a bit stale :)

Copy link
Collaborator

@bcoca bcoca Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all connections at this point should be relying on get_option some older ones might still be using play_context.<data> but this is incorrect as it does not always reflect changes do to modifiers in the task (mostly loops). In no case should you be using variables directly.

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

Successfully merging this pull request may close these issues.

3 participants