lunes, 9 de septiembre de 2024

Ansible first steps

pip --version

pip3 --version


Intall the required software:

dnf install python

dnf install python-pip

pip --version

pip install ansible

ansible --version

pip -V

pip install boto3 botocore



Create a role with AmazonEC2FullAccess with this policy:


{

    "Version": "2012-10-17",

    "Statement": [

        {

            "Effect": "Allow",

            "Action": [

                "sts:AssumeRole"

            ],

            "Principal": {

                "Service": [

                    "ec2.amazonaws.com"

                ]

            }

        }

    ]

}



To see lines in vim, run the following command:

:set nu


Create test.yml the file, add the following:


- name: Ansible Play

  hosts: localhost

  tasks:

  - name:   launching AWS instance using Ansible


    amazon.aws.ec2_instance:

      key_name: Key

      region: us-east-1

      instance_type: t2.micro

      image_id: ami-0182f373e66f89c85

      tags:

        Name: Demo_server



Check the syntax of the file:

ansible-playbook --syntax-check test.yml


ansible-playbook -C test.yml


ansible-playbook test.yml


The ec2 should appear in the console.


Check docs 

ansible-doc -t module -l | grep amazon.aws.ec2_instance

No hay comentarios:

Publicar un comentario