Skip to content

Instantly share code, notes, and snippets.

@krdlab
Created February 12, 2021 11:58
Show Gist options
  • Save krdlab/e429877cac11aee4b98856619a9cb93d to your computer and use it in GitHub Desktop.
Save krdlab/e429877cac11aee4b98856619a9cb93d to your computer and use it in GitHub Desktop.
Ansible で var から comma separated value を作成
- hosts: localhost
gather_facts: false
vars:
db:
replicas:
- id: 1
dns_record: host1
- id: 2
dns_record: host2
tasks:
- set_fact:
records: "{{ db.replicas | map(attribute='dns_record') | list | join(',') }}"
- name: result
debug:
var=records
@krdlab
Copy link
Author

krdlab commented Feb 12, 2021

TASK [result] ***********************************************************************************************************************************************************
ok: [localhost] => {
    "records": "host1,host2"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment