I have a file that has a list of my job API codes, and the status of that API but in the next line.
The api_file
:
"id": "3b96db40-507e-4dd8-b2fd-e0e237fb928f",
"enabled": true,
"id": "3c07b7a7-0165-4017-84c6-b7e7383105a4",
"enabled": true,
"id": "41b2ed8f-8a21-4b3b-a690-2d7f24e577f6",
"enabled": true,
"id": "42767867-0a93-4cc4-93f8-c3893fe63edf",
"enabled": true,
"id": "4278314e-71ec-4e80-ae35-1dd67ceef2bd",
"enabled": false,
"id": "45c0c8c8-d0b6-4d82-87c3-1c66ec08cf1d",
"enabled": true,
"id": "492f0775-f6b8-4cf6-b355-02260513bd5a",
"enabled": true,
.....
I want to move the status line to the API code line (pair the every two lines), and I used sed 'N;s/[\n]//'
command, and the output should look like this:
"id": "3b96db40-507e-4dd8-b2fd-e0e237fb928f","enabled": true,
"id": "3c07b7a7-0165-4017-84c6-b7e7383105a4","enabled": true,
"id": "41b2ed8f-8a21-4b3b-a690-2d7f24e577f6","enabled": true,
"id": "42767867-0a93-4cc4-93f8-c3893fe63edf","enabled": true,
"id": "4278314e-71ec-4e80-ae35-1dd67ceef2bd","enabled": false,
"id": "45c0c8c8-d0b6-4d82-87c3-1c66ec08cf1d","enabled": true,
"id": "492f0775-f6b8-4cf6-b355-02260513bd5a","enabled": true,
This works if I run it in shell command prompt, but when I use it in the Ansible playbook, I got an error:
The playbook:
- name: retrieve the IDs from the integration APIs
shell: "cat api_file | sed 's/^ *//' > merged_api_file"
And the error output:
TASK [retrieve the IDs from the integration APIs] *************************************************************************************************************************
Friday 07 July 2023 16:12:23 +0000 (0:00:00.805) 0:00:04.707 ***********
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "/usr/bin/cat /mnt/stl-server-actions/opsgenie/disable/opsgenie-integrations-2023-07-06-22-15-46.conf | egrep \"\"id\"|\"enabled\"\" | sed 's/^ *//' | sed -e 'N;s/\n//' > /mnt/stl-server-actions/opsgenie/disable/opsgenie-integrations-id-2023-07-06-22-15-46.conf", "delta": "0:00:00.005732", "end": "2023-07-07 16:12:23.294963", "msg": "non-zero return code", "rc": 1, "start": "2023-07-07 16:12:23.289231", "stderr": "sed: -e expression #1, char 4: unterminated `s' command", "stderr_lines": ["sed: -e expression #1, char 4: unterminated `s' command"], "stdout": "", "stdout_lines": []}
What is wrong with the sed
command and how should I correct it?
Thanks!