Config multiple devices

26 views
Skip to first unread message

Tcpip

unread,
Apr 1, 2018, 5:43:09 AM4/1/18
to Ansible Project
hi all,

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

thanks

Oleg Gerasymchuk

unread,
Apr 2, 2018, 3:02:30 PM4/2/18
to ansible...@googlegroups.com
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:
- name: Copy template for host
  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,


Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tcpip

unread,
Apr 3, 2018, 8:46:07 AM4/3/18
to Ansible Project
Hello Oleg

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

Thanks!

Tcpip

unread,
Apr 3, 2018, 1:05:21 PM4/3/18
to Ansible Project
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
---
- hosts: all
  gather_facts: true
  connection: local
  vars:
   cli:
    #host: "{{ inventory_hostname}}"
    username: "{{ username }}"
    password: "{{ password }}"
    authorize: yes
    auth_pass: "{{ auth }}"
  tasks:
    - name: Build Config
      ios_config:
        src: "acl.j2"
        provider: "{{ cli }}"
 ----------------------------------------------------
   acl.j2

{% for name,list in acls.items() %}
ip access-list extended {{name}}
{% for line in list %}
  {{ line }}
{% endfor %}
{% endfor %}

 ----------------------------------------------------

group_vars / all.yml

acls:
  test:
    - deny tcp any any eq 80 log
    - deny tcp any eq 80 any log
    - permit ip any any
  test2:
    - deny udp any any log
    - permit tcp any any
  test3:
    - deny tcp any any eq 80 log
    - deny tcp any eq 80 any log
    - permit ip any any
  test4:
    - deny udp any any log
    - permit tcp any any

Reply all
Reply to author
Forward
0 new messages