最好是这样的列表:
“ itsv_hostgroup”:{WBG,LNZ,...}
- set_fact:
itsv_hostgroup: '{{ itsv_hostgroup | default([]) + ["LNZ"] }}'
cacheable: true
when: (itsv_machine_serial.stdout is match "IBM,02781A6BX") or
(itsv_machine_serial.stdout is match "IBM,02781A6CX") or
(itsv_machine_serial.stdout is match "IBM,02781A6DX")
- debug:
var: itsv_hostgroup
- set_fact:
itsv_hostgroup: '{{ itsv_hostgroup | default([]) + ["WBG"] }}'
cacheable: true
when: (itsv_machine_serial.stdout is match "IBM,022199BF7")
- debug:
var: itsv_hostgroup
- set_fact:
itsv_hostgroup: '{{ itsv_hostgroup | default([]) + ["GBG"] }}'
cacheable: true
when: (itsv_machine_serial.stdout is match "IBM,022199BB7")
- debug:
var: itsv_hostgroup
- set_fact:
itsv_hostgroup: '{{ itsv_hostgroup | default([]) + ["VIE"] }}'
cacheable: true
when: (itsv_machine_serial.stdout is match "IBM,022199BF7") or
(itsv_machine_serial.stdout is match "022199BB7") or
(itsv_machine_serial.stdout is match "IBM,02060CE6R")
- debug:
var: itsv_hostgroup
在此示例中,WBG值最后被VIE值覆盖。
- shell: /usr/bin/uname -L | cut -d ' ' -f2
register: itsv_lparname
- command: /usr/sbin/lsattr -El sys0 -a systemid -F value
register: itsv_machine_serial
- set_fact:
itsv_hostgroup: "LNZ"
cacheable: true
when: (itsv_machine_serial.stdout is match "IBM,02781A6BX") or
(itsv_machine_serial.stdout is match "IBM,02781A6CX") or
(itsv_machine_serial.stdout is match "IBM,02781A6DX")
- debug:
var: itsv_hostgroup
- set_fact:
itsv_hostgroup: "WBG"
cacheable: true
when: (itsv_machine_serial.stdout is match "IBM,022199BF7")
- debug:
var: itsv_hostgroup
- set_fact:
itsv_hostgroup: "GBG"
cacheable: true
when: (itsv_machine_serial.stdout is match "IBM,022199BB7")
- debug:
var: itsv_hostgroup
- set_fact:
itsv_hostgroup: "VIE"
cacheable: true
when: (itsv_machine_serial.stdout is match "IBM,022199BF7") or
(itsv_machine_serial.stdout is match "022199BB7") or
(itsv_machine_serial.stdout is match "IBM,02060CE6R")
- debug:
var: itsv_hostgroup
root@lpgaixmgmtlx01:/etc/ansible/aix>ansible-playbook -i AIXWUKIT, testplay.yml
PLAY [run test play] ******************************************************************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************************************************************
ok: [AIXWUKIT]
TASK [hostgroups : shell] *************************************************************************************************************************************************************************************
changed: [AIXWUKIT]
TASK [hostgroups : command] ***********************************************************************************************************************************************************************************
changed: [AIXWUKIT]
TASK [hostgroups : set_fact] **********************************************************************************************************************************************************************************
skipping: [AIXWUKIT]
TASK [hostgroups : debug] *************************************************************************************************************************************************************************************
ok: [AIXWUKIT] => {
"itsv_hostgroup": []
}
TASK [hostgroups : set_fact] **********************************************************************************************************************************************************************************
ok: [AIXWUKIT]
TASK [hostgroups : debug] *************************************************************************************************************************************************************************************
ok: [AIXWUKIT] => {
"itsv_hostgroup": "WBG"
}
TASK [hostgroups : set_fact] **********************************************************************************************************************************************************************************
skipping: [AIXWUKIT]
TASK [hostgroups : debug] *************************************************************************************************************************************************************************************
ok: [AIXWUKIT] => {
"itsv_hostgroup": "WBG"
}
TASK [hostgroups : set_fact] **********************************************************************************************************************************************************************************
ok: [AIXWUKIT]
TASK [hostgroups : debug] *************************************************************************************************************************************************************************************
ok: [AIXWUKIT] => {
"itsv_hostgroup": "VIE"
}
TASK [print out the hostname of target] ***********************************************************************************************************************************************************************
changed: [AIXWUKIT]