Config multiple devices

all,

I have to configure multiple devices with different configurations, how can I run a single playbook and separate the configurations for each device?

.

Hi Juraj.

I think, you might need to create standard role structure with something like this:

yourrole/

tasks/

main.yml

hostname1.yml

hostname2.yml

hostnameN.yml

files/

hostname1.config

hostname2.config

hostnameN.config

templates/

hostname1.yml.j2

hostname2.yml.j2

hostnameN.yml.j2

In proposed structure only tasks/main.yml file is necessary.

Other files may depends on your needs and might not be included.

In tasks/main.yml you may use something like this:

  • name: Copy configuration for host

copy:

src: “{{ inventory_hostname }}”

dest: /destination_folder_of your config

backup: yes

force: no

or this:

template:

src: “{{ inventory_hostname }}”

dest: /destination_folder_of your config

backup: yes

force: no

or this:

  • name: Import task with host-specific configuration

import_tasks: “{{ inventory_hostname }}.yml”

This is only example describe one of many possible options, without additional details.

Configuration may depends not on hostname, but on other facts, defined by setup module.

Hope it will helps. If you’ll need additional details, feel free to ask and attach please some additional details of necessary configuration.

Regards,

Hello Oleg

Thanks for the tip that is what I was looking for!

Thanks!

Hello ,

I have the following playbook , this is to add acls to my cisco router. I get the template from my jinja2 file and the info is in the group_vars/all.yml

I need this to be applied to Router1 and Router2 but both of them have different type of acls, with this playbook, how can I apply this ?

thanks

bkp.yml