简体   繁体   中英

Unable to execute Python script using Ansible playbook

I have a python script that runs "vgs" command to check the free space in the volume groups available and then creates lvm , using lvcreate command.

When I run this python script locally, I can run it without issues and the lvm gets created as well. But if I run it using Ansible playbook, I've tried with both 'command' and 'shell' modules, it is unable to locate the path for vgs command and fails. It seems it is only looking for /usr/bin:/bin paths. Please help.

which: no vgs in (/usr/bin:/bin)", "No Volume Groups Found", "Space Found in Volume Group:"], "warnings": []}

"stderr": "sh: -c: line 0: syntax error near unexpected token `('\nsh: -c: line 0: `{ which: no vgs in (/usr/bin:/bin) -o VG_NAME --noheadings --units m ; } 2>&1'

It seems it is only looking for '/usr/bin:/bin' paths.

Because interactive and non-interactive shell sessions call different set of rc-files. If you set PATH in rc-files that are sourced only by interactive shell, those settings won't be reflected in non-interactive shells.

Add PATH as an environment variable to the task:

- command: <script_on_target_node>
  environment:
    PATH: <path_string>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM