---
- name: Example of getting index with loop in Ansible
hosts: localhost
vars:
items:
- name: item1
- name: item2
- name: item3
tasks:
- name: Print item with index
debug:
msg: "Item {{ index }}: {{ item.name }}"
loop: "{{ items }}"
loop_control:
index_var: index
〇実行結果
[root@629bed370fc3 workspace]# ansible-playbook sample.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [Example of getting index with loop in Ansible] *****************************************************************************************************
TASK [Print item with index] *****************************************************************************************************************************
ok: [localhost] => (item={'name': 'item1'}) => {
"msg": "Item 0: item1"
}
ok: [localhost] => (item={'name': 'item2'}) => {
"msg": "Item 1: item2"
}
ok: [localhost] => (item={'name': 'item3'}) => {
"msg": "Item 2: item3"
}
PLAY RECAP ***********************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
〇その他
indexに、+1する場合は、{{}}の中に入れる。
- name: Print item with index
debug:
msg: "Item {{ index + 1 }}: {{ item.name }}"
loop: "{{ items }}"
loop_control:
index_var: index
index > 1のときのみ、処理するようにする。
- name: Print item with index
debug:
msg: "Item {{ index }}: {{ item.name }}"
loop: "{{ items }}"
loop_control:
index_var: index
when: index > 1
"/run/flannel/subnet.env: no such file or directory"
[root@kube01 ~]# k describe pod coredns-78fcd69978-srgcc -n kube-system
…
dbox: rpc error: code = Unknown desc = failed to set up sandbox container "74fc30873acfc616154b3457e3e0aa4fd1595b10f826618240ddcdee91a533b0" network for pod "coredns-78fcd69978-srgcc": networkPlugin cni failed to set up pod "coredns-78fcd69978-srgcc_kube-system" network: open /run/flannel/subnet.env: no such file or directory
iDRAC GUI > Configuration > System Settings > Alert Configuration > Test Event
"MEM0001"
Rsyslogサーバでログが確認できることを確認
[root@rsyslog ~]# tail /var/log/messages
...
Apr 25 22:29:52 idrac-XXXXXX Severity: Critical, Category: System Health, MessageID: MEM0001, Message: Multi-bit memory errors are detected on the memory device at location(s) DIMM1. Immediately replace the DIMM.
Apr 25 22:29:52 idrac-BH6GPS3 Severity: Informational, Category: Audit, MessageID: LOG006, Message: Test event generated for message ID MEM0001.