Running Python script via ansible

后端 未结 2 1036
礼貌的吻别
礼貌的吻别 2021-01-01 10:29

I\'m trying to run a python script from an ansible script. I would think this would be an easy thing to do, but I can\'t figure it out. I\'ve got a project structure like th

相关标签:
2条回答
  • 2021-01-01 11:08

    try to use script directive, it works for me

    my main.yml

    ---
    - name: execute install script
      script: get-pip.py
    

    and get-pip.py file should be in files in the same role

    0 讨论(0)
  • 2021-01-01 11:15

    If you want to be able to use a relative path to your script rather than an absolute path then you might be better using the role_path magic variable to find the path to the role and work from there.

    With the structure you are using in the question the following should work:

    - name: run my script!
      command: ./mypythonscript.py
      args:
        chdir: "{{ role_path }}"/files
      delegate_to: 127.0.0.1
      run_once: true
    
    0 讨论(0)
提交回复
热议问题