Robotics StackExchange | Archived questions

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

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.

Asked by quant_ros on 2023-05-02 15:43:15 UTC

Comments

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

Asked by gvdhoorn on 2023-05-03 02:41:20 UTC

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.

Asked by quant_ros on 2023-05-03 13:05:49 UTC

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

Asked by gvdhoorn on 2023-05-03 15:09:31 UTC

Answers