2014-06-17 34 views
1
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:在一个计数上有条件地加载一个组变量

如果count超过1,那么设置组变量。

谢谢!

回答

1

如果我理解正确的话,你想拥有group值仅设置为在rax_count大于1。你要做的这两部剧

- 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 
+0

我与包括文件做了,但所用的同样的逻辑。有没有办法只修改该变量? –

+0

对不起,但我不太清楚你在问什么,你能改述/详细说明吗? –

+0

你已经回答了我的问题,但它需要重复很多代码。我想知道是否只能根据计数设置组变量。如果count> 1,那么有组变量,否则没有它。 –

相关问题