jaytaylor / ansible-kafka

Ansible Kafka role
https://galaxy.ansible.com/jaytaylor/kafka/
Other
67 stars 52 forks source link

Bug with machineidinteger when using LVM partionning (kafka-cfg.yml) #24

Closed ledroide closed 7 years ago

ledroide commented 7 years ago

File : kafka-cfg.yml task name: "Generate generic unique machine id integer" shell command : ( 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-]+' | tr -d '-' || echo '0' ; 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)'

When I use a non-LVM partition, it works because of :

$ mount | grep ' / ' | cut -d' ' -f1
/dev/sda2

And this pattern matches with UUID symlink, so you can pick its UUID :

$ ls -l /dev/disk/by-uuid/ | grep $(mount | grep ' / ' | cut -d' ' -f1 | cut -d'/' -f3) ; echo $?
lrwxrwxrwx 1 root root 10 avril 28 11:48 5c0dc710-1247-402a-b3c7-b6a263c02cc3 -> ../../sda2
0

Output code is 0, and that's okay

But with LVM partitioning :

$ mount | grep ' / ' | cut -d' ' -f1 
/dev/mapper/vg_covfefe-lv_root
$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 28 avril 09:12 1815e505-77d6-47e5-aecf-653404cb8933 -> ../../sda1
lrwxrwxrwx 1 root root 10 28 avril 09:12 9b40461e-6840-4225-8899-421c0e5dcc39 -> ../../dm-0
lrwxrwxrwx 1 root root 10 28 avril 09:12 e63ff395-4c7b-4e14-b690-1cb5c7da371e -> ../../dm-1
$ ls -l /dev/disk/by-uuid/ | grep $(mount | grep ' / ' | cut -d' ' -f1 | cut -d'/' -f3) ; echo $?
1

Output code is 1, and string is empty.

So here is the result of the whole shell command with LVM partitioning :

$  ( 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-]+' | tr -d '-' || echo '0' ; 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)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: need more than 1 value to unpack

And here is the error when playing role :

TASK [jaytaylor.ansible-kafka : Generate generic unique machine id integer] ****
fatal: [sh-opo-1]: FAILED! => {"changed": false, "cmd": "( 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-]+' | tr -d '-' || echo '0' ; 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)'", "delta": "0:00:00.018923", "end": "2017-05-28 08:49:15.438258", "failed": true, "rc": 1, "start": "2017-05-28 08:49:15.419335", "stderr": "Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nValueError: need more than 1 value to unpack", "stdout": "", "stdout_lines": [], "warnings": []} 

Hope it helps you to solve this issue.

Regards, Serge

ledroide commented 7 years ago

I suggest to replace the shell command with :

( test -r /etc/fstab && find /dev/disk/by-uuid/ -type l -printf "%f\n" | sort | head -1 | grep --ignore-case --only-matching --extended-regexp --max 1 '[0-9a-f]{3,}[0-9a-f-]+' | tr -d '-' || echo '0' ; 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)'

Works with CentOS 6.8, CentOS 7.3 and Ubuntu 17.04.

jaytaylor commented 7 years ago

Hey @ledroide,

Thanks for reaching out, I'm totally open to changing this as needed.

Feel free to open a PR and we can fully explore and investigate this.

Best, Jay

ledroide commented 7 years ago

Fix for #25 is in PR

jaytaylor commented 7 years ago

Closing this since PR #25 has been merged!

kknd22 commented 6 years ago

I encountered the issue as well when using release v1.2.0. Do we have a new release contains this fix? Thanks -cl

jaytaylor commented 6 years ago

Thanks for the reminder @kknd22, I just cut v1.3.0.

https://github.com/jaytaylor/ansible-kafka/releases/tag/v1.3.0