我有Ansible用ROS设置了一些Raspberry Pi。 ROS可以很好地安装,但不能让我运行catkin_make:
fatal: [100.100.100.119]: FAILED! => {"changed": true, "cmd": "cd /home/ubuntu/catkin_ws; catkin_make", "delta": "0:00:00.012524", "end": "2019-09-23 13:47:24.918048", "msg": "non-zero return code", "rc": 127, "start": "2019-09-23 13:47:24.905524", "stderr": "/bin/bash: catkin_make: command not found", "stderr_lines": ["/bin/bash: catkin_make: command not found"], "stdout": "", "stdout_lines": []}
这是我的剧本:
- name: make Catkin folders
file:
path: "/home/ubuntu/catkin_ws/src"
state: directory
owner: ubuntu
group: ubuntu
mode: '0775'
tags:
- untested
- name: Clone Git into Catkin Folder
shell: cd /home/ubuntu/catkin_ws/src; git clone https://github.com/xxxxx
become_user: ubuntu
tags:
- untested
- name: Add bashrc
shell: echo "source /opt/ros/melodic/setup.bash" >> /home/ubuntu/.bashrc
become_user: ubuntu
tags:
- untested
- name: Load new ROS env
shell: cd /home/ubuntu/catkin_ws; source /home/ubuntu/.bashrc
become_user: ubuntu
args:
executable: /bin/bash
tags:
- untested
- name: Catkin Make
shell: cd /home/ubuntu/catkin_ws; catkin_make
become_user: ubuntu
tags:
- untested
如果我在运行剧本后登录直到失败,然后手动运行catkin_make可以正常运行,我就很沮丧。
答案 0 :(得分:1)
“ / bin / bash:catkin_make:找不到命令”
这是不言而喻的:这意味着该命令在您尝试启动时不在用户的路径中。
我必须在这里进行猜测,但是从我看到的情况来看,当您添加行catkin_make
时,我相信.bashrc
的路径已在您的source /opt/ros/melodic/setup.bash
文件中设置。如果我是对的,请在下面查看为什么它无法按您的方式工作。
但是首先,您应该纠正剧本中的一些错误/不良做法。
cd XXX
任务中使用shell
,而应该使用chdir
arg来代替,例如以下演示任务:- name: do something in shell
shell: do_something
args:
chdir: /home/my/user
您正在将shell
用于具有现有更安全和幂等的ansible模块的操作。例如,您可以使用lineinfile
将行添加到文件中,或使用git
克隆git存储库。
您将在shell
任务中自行采购[.bashrc],而无需启动任何其他命令。这不会做任何事情。任务一旦完成,一切都会丢失。
从以上所有记录中,我将尝试这种方法。只有最后一个任务才能真正解决您的问题(如果我的猜测是正确的话):
- name: make Catkin folders
file:
path: "/home/ubuntu/catkin_ws/src"
state: directory
owner: ubuntu
group: ubuntu
mode: '0775'
tags:
- untested
- name: Clone Git into Catkin Folder
git:
repo: https://github.com/xxxxx
dest: /home/ubuntu/catkin_ws/src
become_user: ubuntu
tags:
- untested
- name: Add bashrc
lineinfile:
path: /home/ubuntu/.bashrc
line: source /opt/ros/melodic/setup.bash
become_user: ubuntu
tags:
- untested
- name: Catkin Make with env loaded
shell: |-
source /home/ubuntu/.bashrc
catkin_make
become_user: ubuntu
args:
executable: /bin/bash
chdir: /home/ubuntu/catkin_ws
tags:
- untested