-1

私はec2インスタンスを作成しましたが、そのプレイブックの下で無制限に役割を呼び出そうとしているときに、 ローカルマシンでec2インスタンスを使用してロールが実行されます。動的インベントリを使用してEC2インスタンスでロールを実行するには?

- name: Provision an EC2 Instance 
    hosts: localhost 
    connection: local 
    gather_facts: False 
    tags: provisioning 
    vars: 
    secret_key: "{{ secret_key }}" 
    access_key: "{{ access_key }}" 
    region: us-east-1 

- hosts: localhost 
    roles: 
    - sdirect 

私は動的インベントリを使用しました。誰も助けてくれるか、何か提案できますか?おかげさまで ここで

答えて

0

は、私はEC2インスタンスを作成し、ec2.pyダイナミックな在庫を使用して、その上に自分の役割を実行するために使用していますという単純な例です:

- name: Provision an EC2 Instance 
    hosts: localhost 
    connection: local 
    gather_facts: False 
    tags: provisioning 
    vars: 
    secret_key: "{{ secret_key }}" 
    access_key: "{{ access_key }}" 
    region: us-east-1 
    tasks: 
    - role: create-ec2-role 
    - name: Refresh the ec2.py cache 
     shell: ./inventory/ec2.py --refresh-cache # location of your ec2.py inventory 
     changed_when: no 

    - name: Refresh inventory 
     meta: refresh_inventory 
# Let suppose you have assign the Name "my_instance" to your Instance 
- hosts: tag_Name_my_instance 
    # I assume that you have created the ubuntu ec2 instance and ssh key is in your ssh agent 
    remote_user: ubuntu 
    roles: 
    - myrole 

私はあなたがどこ同じディレクトリにディレクトリ名inventoryを持っていることをassueあなたは、次のファイルと脚本を持っている:

. 
|-- ec2.ini 
|-- ec2.py 
`-- hosts 

hostsファイルの内容は単純です:

[localhost] 
127.0.0.1 

だけこのコマンドを使用して、脚本を実行するには:

ansible-playbook -i inventory/hosts yourplaybook.yml 

希望あなた

助けるかもしれません