0

while doing rolling restart of cluster using ansible i want run python script to verify the rebooted came back without any issues. so i'm trying to run the python script passing arguments using ansible. below is the code i'm using it fails

ERROR! this task 'python' has extra params, which is only allowed in the following modules: command, win_command, shell, win_shell, script, include, include_vars, include_tasks, include_role, import_tasks, import_role, add_host, group_by, set_fact, raw, meta

- hosts: tag_name
  gather_facts: yes
  become: true
  serial: 1
  tasks:
    - name: execute python script
      local_action: python script.py -r us-east-1,us-west-2 -n tag -e test -s tag -k "pemfile" -u ec2-user
2
  • For future reference, when you paste preformatted code into the post, immediately select it and type Ctrl+K or click the {} button in the interface. That will format the code properly. Commented Jan 3, 2019 at 20:18
  • sure thanks. will do that next time Commented Jan 3, 2019 at 20:46

1 Answer 1

2

I believe the error is correct as 'command' and 'shell' are two most common modules for which you can specify the arguments. To execute the python script on the local host with arguments, use 'command' along with 'local_action' as below.

local_action: command python script.py -r us-east-1,us-west-2 -n tag -e test -s tag -k "pemfile" -u ec2-user
Sign up to request clarification or add additional context in comments.

9 Comments

to use command i need to copy the script to remote node and inside the python script i'm using some files in the same repo. woudn't have access from the machine i'm sshing to. i want to run the python script locally.
tried failed with sudo error. so it tries ssh from remote host back to my local machine? fatal: [myhost -> 127.0.0.1]: FAILED! => { "changed": false, "failed": true, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1
it worked if i make the gather_facts: no. can i use same play-book few commands to run on remote host and few on local?
the delegate_to directive can be used to select specific hosts for specific tasks. I believe you can try running your original code by adding the 'command; module. Try this: local_action: command python script.py -r us-east-1,us-west-2 -n tag -e test -s tag -k "pemfile" -u ec2-user
I'm trying to run one command in remote host then run the python script from local if use below its trying to ssh from remote machine to local - hosts: tag gather_facts: yes become: true serial: 1 tasks: - name: Reboot task command: /sbin/reboot - name: execute install script local_action: command python script.py -r us-east-1,us-west-2 -n tag -e test -s tag -k "pemfile" -u ec2-user
|

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.