Difference between revisions of "Ansible: create Amazon ec2 instance"

From wikieduonline
Jump to navigation Jump to search
Tags: Mobile web edit, Mobile edit
 
(33 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
 +
* https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_module.html
 +
 +
#!/usr/bin/env ansible-playbook
 +
 +
- [[hosts:]] localhost
 +
  [[connection:]] local
 +
  [[become:]] False
 +
 +
  tasks:
 +
    - amazon.aws.[[ec2]]:
 +
        [[key_name]]: mykey
 +
        region: us-east-1
 +
        [[instance_type]]: [[t3.nano]]
 +
        image: [[ami]]-07c1207a9d40bc3bd
 +
        [[vpc_subnet_id:]] subnet-968913da
 +
        wait: yes
 +
        count: 1
 +
        [[assign_public_ip:]] yes
 +
 +
 +
 +
 +
#!/usr/bin/env ansible-playbook
 +
  - name: Status ec2 instances
 +
  hosts: 127.0.0.1
 +
  vars:
 +
    ansible_python_interpreter: "/usr/bin/python3"
 +
  connection: local
 +
  tasks:
 +
   - ec2:
 +
      key_name: YOUR_KEY_NAME
 +
      profile: XXXX
 +
      region: us-east-1
 +
      instance_type: t3.nano
 +
      image: ami-0f4768a55eaaac3d7
 +
      wait: yes
 +
      count: 1
 +
      assign_public_ip: no 
 +
 +
 +
== Errors ==
 
<pre>
 
<pre>
- amazon.aws.ec2:
+
WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
    key_name: mykey
+
 
    instance_type: t2.micro
+
PLAY [localhost] *****************************************************************************************************************************************************************************************************************************
    image: ami-123456
+
 
    wait: yes
+
TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
    group: webserver
+
ok: [localhost]
    count: 3
+
 
    vpc_subnet_id: subnet-29e63245
+
TASK [amazon.aws.ec2] ************************************************************************************************************************************************************************************************************************
    assign_public_ip: yes
+
fatal: [localhost]: FAILED! => {"changed": false, "msg": "No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials"}
 +
 
 +
PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
 +
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
 +
 
 
</pre>
 
</pre>
 
  
  
 
== Related terms ==
 
== Related terms ==
 
* [[Ansible playbooks examples]]
 
* [[Ansible playbooks examples]]
 
+
* <code>[[aws ec2 run-instances]]</code>, <code>[[aws ec2 describe-instances]]</code>
 +
* <code>[[aws configure list]]</code>
 +
* [[amazon.aws.ec2_key]]
 +
* [[Manage AWS infrastructure using Ansible]]
 +
* [[Create VM]]
 +
* [[Terraform]]: <code>[[aws_instance]]</code>
  
 
== See also ==
 
== See also ==

Latest revision as of 06:15, 31 March 2022

#!/usr/bin/env ansible-playbook 

- hosts: localhost
  connection: local
  become: False

  tasks:
    - amazon.aws.ec2:
       key_name: mykey
       region: us-east-1
       instance_type: t3.nano
       image: ami-07c1207a9d40bc3bd
       vpc_subnet_id: subnet-968913da
       wait: yes
       count: 1
       assign_public_ip: yes



#!/usr/bin/env ansible-playbook
 - name: Status ec2 instances
  hosts: 127.0.0.1 
  vars:
    ansible_python_interpreter: "/usr/bin/python3"
  connection: local
  tasks:
   - ec2:
      key_name: YOUR_KEY_NAME
      profile: XXXX 
      region: us-east-1
      instance_type: t3.nano
      image: ami-0f4768a55eaaac3d7
      wait: yes
      count: 1 
      assign_public_ip: no 


Errors[edit]

WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [localhost] *****************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [amazon.aws.ec2] ************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials"}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


Related terms[edit]

See also[edit]

Advertising: