История изменений
Исправление SpaceRanger, (текущая версия) :
---
- name: update config
hosts: all
vars:
names: "{{ out.files|map(attribute='path')|map('basename')|list}}"
tasks:
- name: get list of existing instances
find:
paths: /home/user
file_type: directory
use_regex: yes
patterns: "test_\\d+"
register: out
- debug: var=names
- name: copy output to a file
local_action:
module: copy
content: "{{ out.stdout_lines }}"
dest: "{{ playbook_dir }}/{{ inventory_hostname }}"
- name: update local var file
delegate_to: localhost
local_action: command python main.py "{{ inventory_hostname }}"
- name: delete temporary config file
delegate_to: localhost
file:
path: "{{ playbook_dir }}/{{ inventory_hostname }}"
state: absent
- name: include VARS for each host
include_vars:
file: "vars/{{ inventory_hostname }}"
name: hui
- name: what is type
debug:
msg: "{{ hui | type_debug }}"
- name: test lookup
debug:
msg: "Host is {{ item.key }}, port1 is {{ item.value.port1 }} and port2 is {{ item.value.port2 }}"
loop: "{{ lookup('dict', hui.namehost) }}"
- name: templating
template:
src: sys.config.j2
dest: "/home/user/{{ item.key }}/sys.config"
loop: "{{ lookup('dict', hui.namehost) }}"
- name: copy nt-adec to target hosts
copy:
src: nt-adec.bin
dest: "/home/user/{{ item.key }}/pipe"
owner: user
group: user
mode: '755'
loop: "{{ lookup('dict', hui.namehost )}}"
namehost:
test_1:
port1: 1201
port2: 5601
test_10:
port1: 12010
port2: 56010
test_2:
port1: 1202
port2: 5602
test_3:
port1: 1203
port2: 5603
test_4:
port1: 1204
port2: 5604
test_5:
port1: 1205
port2: 5605
test_6:
port1: 1206
port2: 5606
test_7:
port1: 1207
port2: 5607
test_8:
port1: 1208
port2: 5608
test_9:
port1: 1209
port2: 5609
Кароч, вот готовое решение. Всем спасибо.
Исправление SpaceRanger, :
---
- name: update config
hosts: all
vars:
names: "{{ out.files|map(attribute='path')|map('basename')|list}}"
tasks:
- name: get list of existing instances
find:
paths: /home/user
file_type: directory
use_regex: yes
patterns: "test_\\d+"
register: out
- debug: var=names
- name: copy output to a file
local_action:
module: copy
content: "{{ out.stdout_lines }}"
dest: "{{ playbook_dir }}/{{ inventory_hostname }}"
- name: update local var file
delegate_to: localhost
local_action: command python main.py "{{ inventory_hostname }}"
- name: delete temporary config file
delegate_to: localhost
file:
path: "{{ playbook_dir }}/{{ inventory_hostname }}"
state: absent
- name: include VARS for each host
include_vars:
file: "vars/{{ inventory_hostname }}"
name: hui
- name: what is type
debug:
msg: "{{ hui | type_debug }}"
- name: test lookup
debug:
msg: "Host is {{ item.key }}, port1 is {{ item.value.port1 }} and port2 is {{ item.value.port2 }}"
loop: "{{ lookup('dict', hui.namehost) }}"
- name: templating
template:
src: sys.config.j2
dest: "/home/user/{{ item.key }}/sys.config"
loop: "{{ lookup('dict', hui.namehost) }}"
- name: copy nt-adec to target hosts
copy:
src: nt-adec.bin
dest: "/home/user/{{ item.key }}/pipe"
owner: user
group: user
mode: '755'
loop: "{{ lookup('dict', hui.namehost )}}"
namehost:
test_1:
port1: 1201
port2: 5601
test_10:
port1: 12010
port2: 56010
test_2:
port1: 1202
port2: 5602
test_3:
port1: 1203
port2: 5603
test_4:
port1: 1204
port2: 5604
test_5:
port1: 1205
port2: 5605
test_6:
port1: 1206
port2: 5606
test_7:
port1: 1207
port2: 5607
test_8:
port1: 1208
port2: 5608
test_9:
port1: 1209
port2: 5609
Кароч, вот готовое решение. Всем спасибо.
Исправление SpaceRanger, :
---
- name: update config
hosts: all
tasks:
- name: get list of existing instances
shell:
cd /home/observer/test_ansible; ls | grep -E "test_[0-9]+"
register: out
- debug: var=out.stdout_lines
register: foo_result
- name: copy output to a file
local_action:
module: copy
content: "{{ out.stdout_lines }}"
dest: "{{ playbook_dir }}/{{ inventory_hostname }}"
- name: update local var file
delegate_to: localhost
local_action: command python main.py "{{ inventory_hostname }}"
- name: delete temporary config file
delegate_to: localhost
file:
path: "{{ playbook_dir }}/{{ inventory_hostname }}"
state: absent
- name: include VARS for each host
include_vars:
file: "vars/{{ inventory_hostname }}"
name: hui
- name: what is type
debug:
msg: "{{ hui | type_debug }}"
- name: test lookup
debug:
msg: "Host is {{ item.key }}, port1 is {{ item.value.port1 }} and port2 is {{ item.value.port2 }}"
loop: "{{ lookup('dict', hui.namehost) }}"
- name: templating
template:
src: sys.config.j2
dest: "/home/user/{{ item.key }}/sys.config"
loop: "{{ lookup('dict', hui.namehost) }}"
- name: copy nt-adec to target hosts
copy:
src: nt-adec.bin
dest: "/home/user/{{ item.key }}/pipe"
owner: user
group: user
mode: '755'
loop: "{{ lookup('dict', hui.namehost )}}"
namehost:
test_1:
port1: 1201
port2: 5601
test_10:
port1: 12010
port2: 56010
test_2:
port1: 1202
port2: 5602
test_3:
port1: 1203
port2: 5603
test_4:
port1: 1204
port2: 5604
test_5:
port1: 1205
port2: 5605
test_6:
port1: 1206
port2: 5606
test_7:
port1: 1207
port2: 5607
test_8:
port1: 1208
port2: 5608
test_9:
port1: 1209
port2: 5609
Кароч, вот готовое решение. Всем спасибо.
Исходная версия SpaceRanger, :
---
- name: update config
hosts: all
tasks:
- name: get list of existing instances
shell:
cd /home/observer/test_ansible; ls | grep -E "test_[0-9]+"
register: out
- debug: var=out.stdout_lines
register: foo_result
- name: copy output to a file
local_action:
module: copy
content: "{{ out.stdout_lines }}"
dest: "{{ playbook_dir }}/{{ inventory_hostname }}"
- name: update local var file
delegate_to: localhost
local_action: command python main.py "{{ inventory_hostname }}"
- name: delete temporary config file
delegate_to: localhost
file:
path: "{{ playbook_dir }}/{{ inventory_hostname }}"
state: absent
- name: include VARS for each host
include_vars:
file: "vars/{{ inventory_hostname }}"
name: hui
- name: what is type
debug:
msg: "{{ hui | type_debug }}"
- name: test lookup
debug:
msg: "Host is {{ item.key }}, port1 is {{ item.value.port1 }} and port2 is {{ item.value.port2 }}"
loop: "{{ lookup('dict', hui.namehost) }}"
- name: templating
template:
src: sys.config.j2
dest: "/home/user/{{ item.key }}/sys.config"
loop: "{{ lookup('dict', hui.namehost) }}"
- name: copy nt-adec to target hosts
copy:
src: nt-adec.bin
dest: "/home/user/{{ item.key }}/pipe"
owner: user
group: user
mode: '755'
loop: "{{ lookup('dict', hui.namehost )}}"
Кароч, вот готовое решение. Всем спасибо.