依存

2017-04-06 10 views
1

Senarioと同じ脚本で二つの異なるホストとの2つの演劇:依存

1. I need to run two plays in a single playbook. 
2. The second play should run after the first play. 
3. The first play create few instance and update the inventory file by making new group. 
4. Second play uses the updated group and install few packages. 

問題:私は別に、両方の戯曲を実行している場合、それは成功です。 しかし、私は同じスクリプトでそれらが必要です。

私が思う問題は両方とも並行して実行されていることです。

ありがとうございます。

--- 
- name: ec2 
    hosts: localhost 
    connection: local 
    roles: 
    - launchEc2 
- hosts: ansible 
    gather_facts: Fasle 
    become: yes 
    roles: 
    - python 

OUTPUT:脚本を処理する前に

PLAY [ec2] ********************************************************************* 

TASK [setup] ******************************************************************* 
ok: [127.0.0.1] 

TASK [launchEc2 : include_vars] ************************************************ 
ok: [127.0.0.1] 

TASK [launchEc2 : Launch new ec2 instance] ************************************* 
changed: [127.0.0.1] 

TASK [launchEc2 : Add ec2 ip to the hostgroup] ********************************* 
changed: [127.0.0.1] => (item={.....}) 

TASK [launchEc2 : wait for SSh to come up] ************************************* 
ok: [127.0.0.1] => (item={.....}) 

PLAY [ansible] ***************************************************************** 

TASK [python : install python] ************************************************* 
skipping: [34.203.228.19] 

PLAY RECAP ********************************************************************* 
127.0.0.1     : ok=5 changed=2 unreachable=0 failed=0 
34.203.228.19    : ok=0 changed=0 unreachable=0 failed=0 
+0

私はあなたが手動で 'add_host'を使う代わりにホストファイルを更新するという問題があると思います。 –

+0

私はホストを更新するためにlineinfileを使用しています....問題がありますか? –

答えて

1

Ansibleロードインベントリ。

あなたのケースでは、2回目のプレイは、最初のプレーでの変更前と同じインベントリを持ちます。

一般に、クラウドホストをプロビジョニングするときは、add_hostを使用して新しいホストをメモリインベントリに動的に追加することができます。

在庫変更後にmeta: refresh_inventoryに電話することもできますが、静的在庫の更新には不向きです。

+0

「add_host」で試してみましたが、セカンドプレイは実行可能ですが、** –

+0

を追加してplaybookスニペットを追加し、_original_質問に出力を記録します。 –

+0

2回目の再生前に 'meta:refresh_inventory'を追加する必要がありますか? –