0

I am using win_shell module to execute a command op remote host. But ansible is not setting the value the right way (or me of course)

I set a variable that enable or disable scheduled tasks based on user input in Ansible Tower

tasks: 
  - name: disable enable tasks without ebs based on user input
    win_shell: '"{{ command_to_execute }}" -TaskName "{{ task_name }}"'

the user input in Ansible tower:

    - command_to_execute: Enable-ScheduledTask
     or 
    - command_to_execute: Disable-ScheduledTask

The job succeded but not enabeling or disableing anything. in the output i can see that:

    "cmd": "\"[u'Enable-ScheduledTask']\" -TaskName 
     \"start_something\"",

so instead of

      Enable-ScheduledTask 

i get

      [u'Enable-ScheduledTask'] .

Why is that?

1 Answer 1

1

It looks like you've got list of one element 'Enable-ScheduledTask' in your {{ command_to_execute }} variable. The most short and straightforward way would be using {{ command_to_execute | first }}

Sign up to request clarification or add additional context in comments.

1 Comment

That seems like an important first step, but note the the {{ command_to_execute }} value is enclosed in "...". In PowerShell, in order to execute a command whose name is stored in a quoted string, you must prepend &, the call operator: '& "{{ ... ; alternatively, simply omit the enclosing double quotes in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.