Skip to content

Instantly share code, notes, and snippets.

@pavelanni
Last active December 20, 2017 03:56
Show Gist options
  • Save pavelanni/fad353d2b19c572cf5131bc0d99743d8 to your computer and use it in GitHub Desktop.
Save pavelanni/fad353d2b19c572cf5131bc0d99743d8 to your computer and use it in GitHub Desktop.
Create sequential file names or EC2 instance tags with Ansible
---
- name: naming sequence
connection: local
hosts: localhost
vars:
- names: ['cs','cs','cs','cs','cs',]
- numbers: []
- n_instances: 5
tasks:
- name: create a list of numbers
set_fact:
numbers: "{{numbers}} + ['{{item}}']"
with_sequence: start=1 end={{ n_instances }} format=%03d
- name: parallel loop
debug:
msg: "instance name is {{ item.0 }}-{{ item.1 }}"
with_together:
- "{{ names }}"
- "{{ numbers }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment