Как насчет этого?
---
- hosts: ciscos
gather_facts: False
connection: local
tasks:
- name: Fact My Inventory
set_fact:
myinventory: "{{ ansible_play_batch | shuffle }}"
run_once: True
delegate_to: localhost
- name: Fact limited_selection
set_fact:
limited_selection: "{{ myinventory[0:max_index|int] }}"
run_once: True
delegate_to: localhost
- name: Create Inventory
add_host:
name: '{{ item }}'
groups: limited_selection
with_items: "{{ limited_selection }}"
delegate_to: localhost
- hosts: limited_selection
gather_facts: no
tasks:
- name: Debug
debug:
msg: "I'm in the limited selection group!"
Будьте осторожны с play_hosts
, поскольку он устарел.
Примечание. Я сохранил книгу с
blockquote>connection:ciscos
вместоlocalhost
для обучения и отображения переменныхansible_play_batch
иmax_index
. Лучше иметь локальную игру сgroups
вместоdelegate_to:localhost
Добавить это:
$message=explode($message, "\n")[0];
Это должно работать.