Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
Last active March 6, 2020 12:47
Show Gist options
  • Save heiwa4126/2979c6579bc5f6919ec7b6033c37b317 to your computer and use it in GitHub Desktop.
Save heiwa4126/2979c6579bc5f6919ec7b6033c37b317 to your computer and use it in GitHub Desktop.
Ansibleのjoinとsequenceのサンプル
- name: join and sequence example
hosts: localhost
become: no
gather_facts: False
vars:
data: [foo, bar, baz]
tasks:
-
name: join example
debug: msg="{{ data|join(', ') }}"
-
name: sequence example
debug: msg="{{ 'count %02d'|format(item|int) }}"
with_sequence: count=4
-
name: sequence example 2
debug: var=item
with_sequence: start=3 end=1 stride=-1 format=%08d
@heiwa4126
Copy link
Author

予測はつくでしょーが、以下のような出力が得られます。

PLAY [join and sequence example] *********************************************************************

TASK [join example] **********************************************************************************
ok: [localhost] =>
  msg: foo, bar, baz

TASK [sequence example] ******************************************************************************
ok: [localhost] => (item=1) =>
  msg: count 01
ok: [localhost] => (item=2) =>
  msg: count 02
ok: [localhost] => (item=3) =>
  msg: count 03
ok: [localhost] => (item=4) =>
  msg: count 04

TASK [sequence example 2] ****************************************************************************
ok: [localhost] => (item=00000003) =>
  ansible_loop_var: item
  item: '00000003'
ok: [localhost] => (item=00000002) =>
  ansible_loop_var: item
  item: '00000002'
ok: [localhost] => (item=00000001) =>
  ansible_loop_var: item
  item: '00000001'

PLAY RECAP *******************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0   ignored=0

@heiwa4126
Copy link
Author

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