A
A
Alexander2015-11-04 15:11:54
Mikrotik
Alexander, 2015-11-04 15:11:54

Is it possible in Ansible to perform tasks related to another host when passing each host?

Good day!
Wrote a playbook for setting up a fresh virtual machine and deploying the necessary set of software on it. A domain is attached to each virtual machine, which I want to assign to this virtual machine in the DNS settings on Mikrotik.
Adding a record is not difficult, but it became interesting whether this can be done using the same playbook? Something like this will come out in more detail ...
Hosts that need to be configured or updated will be added to the hosts file. To configure and update servers, a playbook has been created, which, based on the parameters in hosts, configures the virtual machine for a specific domain, etc. That is, each host has its own domain in the config (below is an example of the config).
I would like Ansible to climb on Mikrotik at the end and add the domain (s) for this host.
Is it possible?
Example hosts with parameters:

[vms]
192.168.0.2 domain=sub1.test.com db_name=sub1 vhost_type=yii2
192.168.0.3 domain=sub2.test.com db_name=sub2 vhost_type=ci
192.168.0.4 domain=sub3.test.com db_name=sub3 vhost_type=zf

[mikrotik]
192.168.0.254 ansible_ssh_user=ansible ansible_ssh_pass=ansible

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
neol, 2015-11-04
@Gemini_13

docs.ansible.com/ansible/playbooks_delegation.html... Looks
like it.

P
Puma Thailand, 2015-11-04
@opium

You can use data from other hosts
, for example, in the template I use the ip of servers from the radish group
{% if 'redis-servers' in group_names %}
{% for host in groups['rails-servers'] %}
{{ hostvars[host ]['ansible_eth0']['ipv4']['address'] }}
{% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question