When I assign a variable containing double quotes to another variable the double quotes (") sometimes get converted to single quotes ('). .can you please suggest how to solve this.
TASK [asm_pdb_disk_mapping : debug] ************************************************************************************************************************************
ok: [10.0.0.10] => {
"device_name": {
"changed": true,
"cmd": "a1=( \"xvda\" \"xvdb\" \"xvdc\" \"xvdd\" \"xvde\" \"xvdf\" \"xvdg\" \"xvdh\" \"xvdi\" \"xvdj\" \"xvdk\" \"xvdl\" \"xvdm\" \"xvdn\" \"xvdo\" \"xvdp\" \"xvdq\" \"xvdr\" \"xvds\" \"xvdt\" \"xvdu\" \"xvdv\" \"xvdw\" \"xvdx\" \"xvdy\" \"xvdz\")\nfor i in `cat /tmp/volume.txt | sed -e 's/\\[//' | sed -e 's/\\]//' | sed -e 's/\\\"//g' | sed -e 's/,/ /g'`\ndo\na2+=(\"$i\")\ndone\na3=()\nfor i in \"${a1[@]}\"; do\nskip=\nfor j in \"${a2[@]}\"; do\n [[ $i == $j ]] && { skip=1; break; }\ndone\n [[ -n $skip ]] || a3+=(\"$i\")\ndone\njoined=$(printf \",\"\\\"\"dev/\"%s\"\\\"\" \"${a3[@]:0:2}\") \necho \"[\"${joined:1}\"]\"\n",
"delta": "0:00:00.088902",
"end": "2020-02-17 21:50:56.868731",
"failed": false,
"rc": 0,
"start": "2020-02-17 21:50:56.779829",
"stderr": "",
"stderr_lines": [],
"stdout": "[\"dev/xvdj\",\"dev/xvdk\"]",
"stdout_lines": [
"[\"dev/xvdj\",\"dev/xvdk\"]"
]
}
}
Expected value to store in variable : [\"dev/xvdj\",\"dev/xvdk\"]
But it is storing this variable value: [u'dev/xvdj', u'dev/xvdk']
Tel me know how to solve this issue.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CADG%3DkotAgP8RdwBmyHjG9nv8GO-0Kqr5Zt%3DH_FTfmfk09Aomwg%40mail.gmail.com.
More explanation about playbook, hope you did not chance to see that, please check once.
cat /tmp/volume.txt #Has list of disk attached to server, which needs to excluded
["xvda", "xvdb", "xvdc", "xvdd", "xvde", "xvdf", "xvdg", "xvdh", "xvdi"]
# disk.yml
disk_count.stdout: 2 #number of disk need to add to server.
- name: Call devicecheck script
shell: |
a1=( "xvda" "xvdb" "xvdc" "xvdd" "xvde" "xvdf" "xvdg" "xvdh" "xvdi" "xvdj" "xvdk" "xvdl" "xvdm" "xvdn" "xvdo" "xvdp" "xvdq" "xvdr" "xvds" "xvdt" "xvdu" "xvdv" "xvdw" "xvdx" "xvdy" "xvdz")
for i in `cat /tmp/volume.txt | sed -e 's/\[//' | sed -e 's/\]//' | sed -e 's/\"//g' | sed -e 's/,/ /g'`
do
a2+=("$i")
done
a3=()
for i in "${a1[@]}"; do
skip=
for j in "${a2[@]}"; do
[[ $i == $j ]] && { skip=1; break; }
done
[[ -n $skip ]] || a3+=("$i")
done
joined=$(printf ","\""dev/"%s"\"" "${a3[@]:0:{{disk_count.stdout}}}")
echo "["${joined:1}"]"
register: device_name
when: inventory_hostname in groups['dbserver']
- name: Register linux jump host with variable |device_name
add_host:
name: "10.0.0.20"
PLAY1VAR_NEW01: "{{ device_name.stdout }}"
register: PLAY1VAR_NEW01
when: inventory_hostname in groups['dbserver']
- debug: var=PLAY1VAR_NEW01
when: inventory_hostname in groups['dbserver']
- name: terraform variable store tasks |device_name
shell: |
echo {{ hostvars["10.0.0.20"]["PLAY1VAR_NEW01"] }} > /tmp/device_name
when: inventory_hostname in groups['controller_servers']
register: terraform_disk
#
=====================================Debug Value======================================================================================
#ansible-playbook –I inventory disk.yml –vvv
TASK [asm_pdb_disk_mapping : debug] ************************************************************************************************************************************
task path: /infra/infracode/automation_deployment/ansible/dynamic_tags/asm_pdb_disk_mapping/tasks/asm_pdb_disk_mapping.yml:219
ok: [10.0.0.10] => {
"device_name": {
"changed": true,
"cmd": "a1=( \"xvda\" \"xvdb\" \"xvdc\" \"xvdd\" \"xvde\" \"xvdf\" \"xvdg\" \"xvdh\" \"xvdi\" \"xvdj\" \"xvdk\" \"xvdl\" \"xvdm\" \"xvdn\" \"xvdo\" \"xvdp\" \"xvdq\" \"xvdr\" \"xvds\" \"xvdt\" \"xvdu\" \"xvdv\" \"xvdw\" \"xvdx\" \"xvdy\" \"xvdz\")\nfor i in `cat /tmp/volume.txt | sed -e 's/\\[//' | sed -e 's/\\]//' | sed -e 's/\\\"//g' | sed -e 's/,/ /g'`\ndo\na2+=(\"$i\")\ndone\na3=()\nfor i in \"${a1[@]}\"; do\nskip=\nfor j in \"${a2[@]}\"; do\n [[ $i == $j ]] && { skip=1; break; }\ndone\n [[ -n $skip ]] || a3+=(\"$i\")\ndone\njoined=$(printf \",\"\\\"\"dev/\"%s\"\\\"\" \"${a3[@]:0:2}\") \necho \"[\"${joined:1}\"]\"\n",
"delta": "0:00:00.089253",
"end": "2020-02-18 10:28:59.483863",
"failed": false,
"rc": 0,
"start": "2020-02-18 10:28:59.394610",
"stderr": "",
"stderr_lines": [],
"stdout": "[\"dev/xvdj\",\"dev/xvdk\"]", #This output we want to capture in subsequent tasks
"stdout_lines": [
"[\"dev/xvdj\",\"dev/xvdk\"]"
]
}
}
TASK [asm_pdb_disk_mapping : debug] ************************************************************************************************************************************
task path: /infra/infracode/automation_deployment/ansible/dynamic_tags/asm_pdb_disk_mapping/tasks/asm_pdb_disk_mapping.yml:230
ok: [10.0.0.10] => {
"PLAY1VAR_NEW01": {
"add_host": {
"groups": [],
"host_name": "10.0.0.20",
"host_vars": {
"PLAY1VAR_NEW01": [
"dev/xvdj",
"dev/xvdk"
]
}
},
"changed": true,
"failed": false
}
}
TASK [asm_pdb_disk_mapping : debug] ************************************************************************************************************************************
task path: /infra/infracode/automation_deployment/ansible/dynamic_tags/asm_pdb_disk_mapping/tasks/asm_pdb_disk_mapping.yml:243
ok: [10.0.0.10] => {
"terraform_disk": {
"changed": false,
"skip_reason": "Conditional result was False",
"skipped": true
}
}
ok: [10.0.0.20] => {
"terraform_disk": {
"changed": true,
"cmd": "echo [u'dev/xvdj', u'dev/xvdk'] > /tmp/device_name\n", #Expected Value >> "[\"dev/xvdj\",\"dev/xvdk\"]",
"delta": "0:00:00.004322",
"end": "2020-02-17 23:29:15.619772",
"failed": false,
"rc": 0,
"start": "2020-02-17 23:29:15.615450",
"stderr": "",
"stderr_lines": [],
"stdout": "",
"stdout_lines": []
}
}
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwNowDf2ixf1%2Bgi0KL5RUHPBoHgZE_wpYQPqm74TZXObvA%40mail.gmail.com.
Hi Disk,More explanation about playbook, hope you did not chance to see that, please check once.
cat /tmp/volume.txt #Has list of disk attached to server, which needs to excluded
["xvda", "xvdb", "xvdc", "xvdd", "xvde", "xvdf", "xvdg", "xvdh", "xvdi"]
# disk.yml
disk_count.stdout: 2 #number of disk need to add to server.
- name: Call devicecheck script
shell: |
a1=( "xvda" "xvdb" "xvdc" "xvdd" "xvde" "xvdf" "xvdg" "xvdh" "xvdi" "xvdj" "xvdk" "xvdl" "xvdm" "xvdn" "xvdo" "xvdp" "xvdq" "xvdr" "xvds" "xvdt" "xvdu" "xvdv" "xvdw" "xvdx" "xvdy" "xvdz")