I stuck a bit with ansible and autogenerated id, I have multiple mysql master - slaves server for that I need to generate a server-id.
my idea was to do something like this:
- name: generate repli-id
shell: hostname -I | sed -e 's/ \+\([a-z0-9]\+\:\)\+[a-z0-9]\+//' | sed -e 's/ /\n/' | grep -v '^$' | tail -1 | awk -F. '{print $3 * 256 + $4}'
register: slave_repli
- debug: var=slave_repli.stdout_lines
- name: rewrite
template: src=templates/root.j2 dest=/root/test.conf
so I get the id generated
TASK [debug] *******************************************************************
task path: /Users/miwi/ansible/roles/test/main.yml:32
ok: [mysqls5slave] => {
"slave_repli.stdout_lines": [
"3698"
]
}
ok: [mysqls5master] => {
"slave_repli.stdout_lines": [
"3699"
]
}
my question is now how do I pass it over to my var file
slave_server_id: {{ slave_server_id }}