ansible:`cd:参数太多`
ansible: `cd: too many arguments`
我正在尝试通过 Jenkins 在我们的 ansible 剧本中添加新部分 运行。我是 cd: too many arguments
.
的错误
ansible 剧本代码
- name: "obfuscating python code"
command: "cd /opt/company_name/{{ app_name }}/current/lib/python3.6/site-packages/{{ app_module }}/ & pyarmor obfuscate --src='.' -r __init__.py & cp -r dist/* . & rm -rf dist & cd -"
jenkins 运行ning ansible playbook 是这样出错的
TASK [python-app : obfuscating python code] ************************************
fatal: [server]: FAILED! => {"changed": true, "cmd": ["cd", "/opt/company_name/app-name/current/lib/python3.6/site-packages/app_name/", "&", "pyarmor", "obfuscate", "--src=.", "-r", "__init__.py", "&", "cp", "-r", "dist/*", ".", "&", "rm", "-rf", "dist", "&", "cd", "-"], "delta": "0:00:00.005432", "end": "2022-04-14 23:02:46.568316", "msg": "non-zero return code", "rc": 1, "start": "2022-04-14 23:02:46.562884", "stderr": "/bin/cd: line 2: cd: too many arguments", "stderr_lines": ["/bin/cd: line 2: cd: too many arguments"], "stdout": "", "stdout_lines": []}
更新:我按照建议更新了代码以及更多命令我想在 运行 pyarmor 之前激活 python 虚拟环境,它现在因 No such file or directory: 'source'
- name: "obfuscating python code"
command: "source /opt/company_name/{{ app_name }}/current/bin/activate && pyarmor obfuscate --src='.' -r __init__.py && cp -fr dist/* . && rm -rf dist"
chdir: /opt/intuitive/{{ app_name }}/current/lib/python3.6/site-packages/{{ app_module }}/
TASK [python-app : obfuscating python code] ************************************
fatal: [server]: FAILED! => {"changed": false, "cmd": "source /opt/company/app-name/current/bin/activate '&&' pyarmor obfuscate --src=. -r __init__.py '&&' cp -fr 'dist/*' . '&&' rm -rf dist", "msg": "[Errno 2] No such file or directory: 'source': 'source'", "rc": 2}
您正在尝试将 shell 功能与 command
模块一起使用。 command
不使用 shell,因此您的整个命令行将作为参数传递给 cd
。当您使用 shell 管道、文件 globbing 等功能时,您应该改用 shell
模块。
您还可以使用该模块的 built-in 设置工作目录支持来缩短您的命令。
- name: Obfuscate python code
shell:
cmd: pyarmor obfuscate --src='.' -r __init__.py && cp -r dist/* . && rm -rf dist
chdir: /opt/company_name/{{ app_name }}/current/lib/python3.6/site-packages/{{ app_module }}
我正在尝试通过 Jenkins 在我们的 ansible 剧本中添加新部分 运行。我是 cd: too many arguments
.
ansible 剧本代码
- name: "obfuscating python code"
command: "cd /opt/company_name/{{ app_name }}/current/lib/python3.6/site-packages/{{ app_module }}/ & pyarmor obfuscate --src='.' -r __init__.py & cp -r dist/* . & rm -rf dist & cd -"
jenkins 运行ning ansible playbook 是这样出错的
TASK [python-app : obfuscating python code] ************************************
fatal: [server]: FAILED! => {"changed": true, "cmd": ["cd", "/opt/company_name/app-name/current/lib/python3.6/site-packages/app_name/", "&", "pyarmor", "obfuscate", "--src=.", "-r", "__init__.py", "&", "cp", "-r", "dist/*", ".", "&", "rm", "-rf", "dist", "&", "cd", "-"], "delta": "0:00:00.005432", "end": "2022-04-14 23:02:46.568316", "msg": "non-zero return code", "rc": 1, "start": "2022-04-14 23:02:46.562884", "stderr": "/bin/cd: line 2: cd: too many arguments", "stderr_lines": ["/bin/cd: line 2: cd: too many arguments"], "stdout": "", "stdout_lines": []}
更新:我按照建议更新了代码以及更多命令我想在 运行 pyarmor 之前激活 python 虚拟环境,它现在因 No such file or directory: 'source'
- name: "obfuscating python code"
command: "source /opt/company_name/{{ app_name }}/current/bin/activate && pyarmor obfuscate --src='.' -r __init__.py && cp -fr dist/* . && rm -rf dist"
chdir: /opt/intuitive/{{ app_name }}/current/lib/python3.6/site-packages/{{ app_module }}/
TASK [python-app : obfuscating python code] ************************************
fatal: [server]: FAILED! => {"changed": false, "cmd": "source /opt/company/app-name/current/bin/activate '&&' pyarmor obfuscate --src=. -r __init__.py '&&' cp -fr 'dist/*' . '&&' rm -rf dist", "msg": "[Errno 2] No such file or directory: 'source': 'source'", "rc": 2}
您正在尝试将 shell 功能与 command
模块一起使用。 command
不使用 shell,因此您的整个命令行将作为参数传递给 cd
。当您使用 shell 管道、文件 globbing 等功能时,您应该改用 shell
模块。
您还可以使用该模块的 built-in 设置工作目录支持来缩短您的命令。
- name: Obfuscate python code
shell:
cmd: pyarmor obfuscate --src='.' -r __init__.py && cp -r dist/* . && rm -rf dist
chdir: /opt/company_name/{{ app_name }}/current/lib/python3.6/site-packages/{{ app_module }}