Error using "colcon build" with Ansible. Works fine manually.

asked 2023-05-02 15:43:15 -0500

quant_ros gravatar image

Hello, I've been able to automate the entire ROS2 and dependency installation process using Ansible. Once that is all done, I'll run the following Ansible task:

  - name: Colcon build
    ansible.builtin.shell: "colcon build"
    args:
      chdir: "/home/{{ansible_user}}/ros2_ws"

That results in an error from Ansible as follows ("navigation" is our package name we're trying to build):

TASK [Colcon build] ***********************************************************************************************
fatal: [172.30.170.32]: FAILED! => {"changed": true, "cmd": "colcon build", "delta": "0:00:02.030637", "end": "2023-05-02 15:24:36.840685", "msg": "non-zero return code", "rc": 1, "start": "2023-05-02 15:24:34.810048", "stderr": "--- stderr: navigation\nCMake Error at CMakeLists.txt:9 (find_package):\n  By not providing \"Findrclcpp.cmake\" in CMAKE_MODULE_PATH this project has\n  asked CMake to find a package configuration file provided by \"rclcpp\", but\n  CMake did not find one.\n\n  Could not find a package configuration file provided by \"rclcpp\" with any\n  of the following names:\n\n    rclcppConfig.cmake\n    rclcpp-config.cmake\n\n  Add the installation prefix of \"rclcpp\" to CMAKE_PREFIX_PATH or set\n  \"rclcpp_DIR\" to a directory containing one of the above files.  If \"rclcpp\"\n  provides a separate development package or SDK, be sure it has been\n  installed.\n\n\n---\nFailed   <<< navigation [0.94s, exited with code 1]", "stderr_lines": ["--- stderr: navigation", "CMake Error at CMakeLists.txt:9 (find_package):", "  By not providing \"Findrclcpp.cmake\" in CMAKE_MODULE_PATH this project has", "  asked CMake to find a package configuration file provided by \"rclcpp\", but", "  CMake did not find one.", "", "  Could not find a package configuration file provided by \"rclcpp\" with any", "  of the following names:", "", "    rclcppConfig.cmake", "    rclcpp-config.cmake", "", "  Add the installation prefix of \"rclcpp\" to CMAKE_PREFIX_PATH or set", "  \"rclcpp_DIR\" to a directory containing one of the above files.  If \"rclcpp\"", "  provides a separate development package or SDK, be sure it has been", "  installed.", "", "", "---", "Failed   <<< navigation [0.94s, exited with code 1]"], "stdout": "Starting >>> navigation\n\nSummary: 0 packages finished [1.22s]\n  1 package failed: navigation\n  1 package had stderr output: navigation", "stdout_lines": ["Starting >>> navigation", "", "Summary: 0 packages finished [1.22s]", "  1 package failed: navigation", "  1 package had stderr output: navigation"]}

PLAY RECAP ********************************************************************************************************
172.30.170.32              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

However, when running the command manually using the below commands, it appears to work fine.

cd /home/ansible/ros2_ws
colcon build

Has anyone else run into this before? I see no difference in what the commands are supposed to be doing. I first tried the Ansible module "command" before moving to the "shell" module with the same result. Any help would be appreciated.

edit retag flag offensive close merge delete

Comments

Environment? Does the Ansible task make sure to source the appropriate setup.bash before trying to invoke colcon?

gvdhoorn gravatar image gvdhoorn  ( 2023-05-03 02:41:20 -0500 )edit

I believe so. Currently using this task to handle that:

  - name: Update .bashrc with /opt/ros/<ros_distribution>/setup.bash
    lineinfile:
      path: /home/{{ansible_user}}/.bashrc
      line: source /opt/ros/{{ros2_distribution}}/setup.bash

Then that's also why I switched from the Ansible command module to the shell module since command bypasses shell stuff like that.

quant_ros gravatar image quant_ros  ( 2023-05-03 13:05:49 -0500 )edit

Just to check I'd add a env | grep -i ros | sort and echo $CMAKE_MODULE_PATH task after the task that sources.

gvdhoorn gravatar image gvdhoorn  ( 2023-05-03 15:09:31 -0500 )edit