1 - name: Test
2 - hosts: webserv
3 connection: local
4 gather_facts: False
5
6 tasks:
7 - name: Provision web instances
8 local_action:
9 module: rax
10 credentials: "{{ rax_cred | mandatory }}"
11 name: "{{ rax_name | default(w0) }}"
12 flavor: "{{ rax_flavor | default(6) }}"
13 image: debian-7-wheezy-pvhvm
14 files:
15 /root/.ssh/authorized_keys: "{{ rax_ssh_keys | mandatory }}"
16 count: "{{ rax_count | default(1) }}"
17 group: "{{ rax_group }}"
18 region: DFW
19 wait: yes
20 state: present
21 register: rax
我有这个ansible-playbook,但由于该组,新服务器的名称附加了一个数字计数器。我希望能够将它用于单个服务器实例以及多个服务器实例。有没有办法可以做类似的事情:
如果count大于1,则设置组变量。
谢谢!
答案 0 :(得分:1)
如果我理解正确,您只想在group
大于1的情况下设置rax_count
值。您必须在两个游戏中执行此操作:
- name: Provision web instances
local_action:
module: rax
credentials: "{{ rax_cred | mandatory }}"
name: "{{ rax_name | default(w0) }}"
flavor: "{{ rax_flavor | default(6) }}"
image: debian-7-wheezy-pvhvm
files:
/root/.ssh/authorized_keys: "{{ rax_ssh_keys | mandatory }}"
count: "{{ rax_count | default(1) }}"
group: "{{ rax_group if rax_count > 1 else None }}"
region: DFW
wait: yes
state: present
register: rax