2017-07-14 8 views
3

EC2のAnsibleを使用してSparkクラスタをセットアップしようとしています。Enabledのインデックスに基づいて異なるグループにEC2ホストを追加する

tasks: 
    - name: creating public instance 
     ec2: 
     aws_access_key: "{{ AWS_ACCESS_KEY_ID }}" 
     aws_secret_key: "{{ AWS_SECRET_ACCESS_KEY }}" 
     instance_type: "t2.micro" 
     instance_tags: { 'name': 'test' } 
     image: "ami-936d9d93" 
     count: "{{ count }}" 
     wait: yes 
     group_id: "sg-47230b20" 
     region: "ap-northeast-1" 
     state: present 
     vpc_subnet_id: "subnet-f4c674ac" 
     assign_public_ip: yes 
     key_name: "test-key" 
     register: public 
     - name: adding host to master 
     add_host: 
      name: "{{ public.instances[0]['public_ip'] }}" 
      groups: master 
      ansible_user: ubuntu 
     - name: adding host to slaves 
     add_host: 
      name: "{{ public.instances[item]['public_ip'] }}" 
      groups: slaves 
      ansible_user: ubuntu 
     with_sequence: start=1 end=3 stride=1 

しかし、私の実行中に以下は、私が「奴隷」にグループ「マスター」とサーバーの残りの部分に最初のサーバーのパブリックIPを追加するサーバーを作成した後、サーバーを作成するタスクでありますこのエラーを取得しています:

{"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute u'1'

誰もが問題であるものを私を助けることができる私は、エラーがどこにあるかを把握することができません。

+0

'item'は、文字列、'である[アイテム| INT] '動作しますが、よりよい解決策のための私の答えが表示されるはずです。 –

答えて

2

あなたはslicingを試してみたいことがあります。

- name: adding host to slaves 
    add_host: 
     name: "{{ item.public_ip }}" 
     groups: slaves 
     ansible_user: ubuntu 
    with_items: "{{ public.instances[1:] }}" 
関連する問題