2017-02-15 4 views
2

私はec2モジュール を使用してAWSに新しいマシンをプロビジョニングし、ホストファイルをローカルに更新して次のタスクが既にホストファイルを使用するようにしようとしています。可能な動的ホストがカスタムインタープリタの使用を拒否しました

ので、プロビジョニングがないと、問題とローカルホストファイルの作成にもあります。hostname -iの簡易印刷で次のタスク(単なるテスト用)が が失敗したが

- name: Provision a set of instances 
     ec2: 
     key_name: AWS 
     region: eu-west-1 
     group: default 
     instance_type: t2.micro 
     image: ami-6f587e1C# For Ubuntu 14.04 LTS use ami-b9b394ca # For Ubuntu 16.04 LTS use ami-6f587e1c 
     wait: yes 
     volumes: 
      - device_name: /dev/xvda 
      volume_type: gp2 
      volume_size: 50 
      wait: true 
     count: 2 
     vpc_subnet_id: subnet-xxxxxxxx 
     assign_public_ip: yes 
     instance_tags: 
      Name: Ansible 
     register: ec2 

    - name: Add all instance private IPs to host group 
     add_host: 
      hostname: "{{ item.private_ip }}" 
      ansible_ssh_user: ubuntu 
      groups: aws 
     with_items: "{{ ec2.instances }}" 

    - local_action: file path=./hosts state=absent 
     ignore_errors: yes 

    - local_action: file path=./hosts state=touch 

    - local_action: lineinfile line="[all]" insertafter=EOF dest=./hosts 

    - local_action: lineinfile line="{{ item.private_ip }} ansible_python_interpreter=/usr/bin/python3" insertafter=EOF dest=./hosts 
     with_items: "{{ ec2.instances }}" 

    - name: Wait for SSH to come up 
     wait_for: 
      host: "{{ item.private_ip }}" 
      port: 22 
      delay: 60 
      timeout: 600 
      state: started 
     with_items: "{{ ec2.instances }}" 

    - name: refreshing inventory cache 
     meta: refresh_inventory 

- hosts: all 
    gather_facts: False 
    tasks: 
    - command: hostname -i 

それは(のpython3がある)のUbuntu 16.04 LTSのPython 2.7にそのために を見つけることができないので、私の動的ホストファイルで、私は次の行を追加します。

ansible_python_interpreter=/usr/bin/python3 

をしかし、ansibleがそれを無視しているようですし、まっすぐに行きますpython 2.7がありません。

私は

meta: refresh_inventory 

インベントリファイルを再ロードしようとしたが、それはどちらか助けていませんでした。 私は何が間違っていますか?

+0

注意してデバッグすることを見つけます。 html – SztupY

+0

@SztupY - はい私は知っています、もしあなたがPython2.xに付属していないUbuntu 16.04を使う必要があるなら、 –

答えて

1

なぜリフレッシュがうまくいかなかったのか分かりませんが、add_hostセクションに設定することをお勧めします。 https://docs.ansible.com/ansible/python_3_support:

- name: Add all instance private IPs to host group 
    add_host: 
     hostname: "{{ item.private_ip }}" 
     ansible_ssh_user: ubuntu 
     groups: aws 
     ansible_python_interpreter: "/usr/bin/python3" 
    with_items: "{{ ec2.instances }}" 

はまた、私はそれが役に立つansibleでのpython 3サポートはまだ少しフレーク状であることを、このタスク

- debug: var=hostvars[inventory_hostname] 
関連する問題