简体   繁体   English

Ansible AWX:当 .yml 和 .py 文件位于 Github 中时,使用 Ansible playbook 触发 python 脚本

[英]Ansible AWX: trigger python script using Ansible playbook when .yml and .py files are located in Github

I am starting to integrate AWX into our environment and would like to move & schedule some python scripts there, but I am facing issue to trigger python script using Ansible playbook.我开始将 AWX 集成到我们的环境中,并希望在那里移动和安排一些 python 脚本,但我遇到了使用 Ansible playbook 触发 python 脚本的问题。 There is .YML and .PY located in the same Github repository & directory. .YML 和 .PY 位于同一个 Github 存储库和目录中。 I trigger Ansible playbook which initiates python script as per below 2 lines (there is more of the code of course) and everything completes OK, but script is not triggered.我触发了 Ansible playbook,它按照以下 2 行启动 python 脚本(当然还有更多代码),一切正常,但没有触发脚本。 Previously all python scripts were located on the host locally and scheduled via windows task scheduler.以前所有的 python 脚本都位于本地主机上,并通过 Windows 任务调度程序进行调度。

CODE:代码:

- name: Checking for duplicate clients

  script: duplicate_clients.py

Seems that Python script on the windows host is even not started, as I do not see python started in the task manager.似乎 Windows 主机上的 Python 脚本甚至没有启动,因为我没有在任务管理器中看到 python 启动。

DEBUG :调试

    <server_XXX> PUT "/runner/project/MISC/duplicate_clients.py" TO "C:\Users\C017317\AppData\Local\Temp\ansible-tmp-1656571782.4292357-31-141461256091413\duplicate_clients.py"
EXEC (via pipeline wrapper)
EXEC (via pipeline wrapper)
changed: [server_XXX] => {
    "changed": true,
    "rc": 0,
    "stderr": "#< CLIXML<Objs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\"><Obj S=\"progress\" RefId=\"0\"><TN RefId=\"0\"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N=\"SourceId\">1</I64><PR N=\"Record\"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>",
    "stderr_lines": [
        "#< CLIXML<Objs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\"><Obj S=\"progress\" RefId=\"0\"><TN RefId=\"0\"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N=\"SourceId\">1</I64><PR N=\"Record\"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>"
3…
META: ran handlers

However, I have tried a different approach to start python script (as I am not sure how exactly it should be done when script is located on Github).但是,我尝试了一种不同的方法来启动 python 脚本(因为我不确定当脚本位于 Github 上时应该如何完成)。

CODE:代码:

- name: Checking for duplicate clients
command: py -3 duplicate_clients.py

DEBUG调试

> EXEC (via pipeline wrapper)
Using module file /usr/local/lib/python3.8/site-packages/ansible/modules/command.py
Pipelining is enabled.
EXEC (via pipeline wrapper)
[WARNING]: No python interpreters found for host
server_XXX (tried ['python3.10', 'python3.9',
'python3.8', 'python3.7', 'python3.6', 'python3.5', '/usr/bin/python3',
'/usr/libexec/platform-python', 'python2.7', 'python2.6', '/usr/bin/python',
'python'])
fatal: [server_XXX]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,

Seems it is looking python on a linux path, though the target host is a windows.似乎它在 linux 路径上寻找 python,尽管目标主机是 windows。

The python script here is not an issue, as it is simply creating a test file.这里的 python 脚本不是问题,因为它只是创建一个测试文件。 Running script locally completes with RC=0.在本地运行脚本以 RC=0 完成。

So the issue has been resolved by providing python executable path.所以这个问题已经通过提供 python 可执行路径解决了。

- name: Checking for duplicate clients
  script: create_file.py
  args: 
    executable: '"C:\Program Files (x86)\Python\python.exe"'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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