ansible-kafka icon indicating copy to clipboard operation
ansible-kafka copied to clipboard

"Generate generic unique machine id integer" fails on LVM root

Open artur-fijalkowski opened this issue 7 years ago • 1 comments

Problem is caused by fact that tr on empty string is ok (command return 0). So tr -d '-' || echo '0' behaves different then expected.

Proper order of commands below

  • name: "Generate generic unique machine id integer"

    NB: This uses a combination of root partition UUID + network interface MAC address.

    shell: ( (test -r /etc/fstab && ls -l /dev/disk/by-uuid/ | grep $(mount | grep ' / ' | cut -d' ' -f1 | cut -d'/' -f3) | grep --ignore-case --only-matching --extended-regexp --max 1 '[0-9a-f]{3,}[0-9a-f-]+' || echo '0') | tr -d '-' ; ifconfig | grep --ignore-case --only-matching --extended-regexp '([0-9a-f]{2}:){5}[0-9a-f]{2}' | tr -d ':' | tr -d '\n') | python -c 'import sys; x, y = sys.stdin.read().split(chr(10))[0:2]; x = int(x, 16); y = int(y, 16); sys.stdout.write((str(x + y)[-9:])); sys.exit(1 if x == 0 and y == 0 else 0)' register: machineidinteger changed_when: False when: kafka_generate_broker_id | bool tags:
    • kafka-cfg

artur-fijalkowski avatar Jan 19 '18 09:01 artur-fijalkowski

Hi @artur-fijalkowski,

Thanks for taking the time to dig in and identify a possible remedy.

PRs welcome :)

jaytaylor avatar Jan 19 '18 19:01 jaytaylor