Get ansible to read value from mysql and/or perl script -
there may better way need altogether. i'll give background first current (non-working) approach.
the goal migrate bunch of servers 1 sles 11 sles 12 making use of ansible playbooks. problem newserver , oldserver supposed have same nfs mounted dir. has done @ beginning of playbook of other tasks can completed. name of dir being created can determined in 2 ways - on oldserver directly or mysql db query volume name on oldserver. newservers named migrate-(oldservername). tried prompt volumename in ansible, apply same name every server. goal recap: dir name must determined oldserver, created on new server.
approach 1: i've created perl script ansible copy newserver , execute mysql query, , create dir itself. there 2 problems - 1) mysql-client needs installed on each server. unneccesary these servers , have uninstalled after query run. 2) copying files , remotely executing them seems bad approach in general.
approach 2: create version of above except run on ansible control machine (where mysql-client installed already) , store values in key:value pairs in file. problems - 1) cannot figure out how in perl script determine hosts ansible running against , have manually enter them perl script. 2) cannot figure out how ansible import values correctly file created.
here's relevant perl code have -
$newserver = migrate-old.server.com ($mig, $oldhost) = split(/\-/, $newserver); $volname=`mysql -u idm-ansible -p -s -n -e "select vol_name assets.servers hostname '$oldhost'";`; open(fh, ">vols.yml"); $values = $newhost{$volname}; print fh "$newhost:$volname\n"; close(fh);
my ansible code on place i've tried , commented out ton of things. can share here if helpful.
approach 3: in ansible mysql query loop on each host. problem - have absolutely no idea how this. way unfamiliar ansible. think prefer try , though.
what best approach here? how go getting right value ansible create correct directory?
please let me know if can clarify anything.
goal recap: dir name must determined oldserver, created on new server.
will magic variables do?
this:
--- - hosts: old-server tasks: - shell: "/get-my-mount-name.sh" register: my_mount_name - hosts: new-server tasks: - shell: "/mount-me.sh --mount_name={{ hostvars['old-server'].my_mount_name.stdout }}"
Comments
Post a Comment