Difference between revisions of "Manage AWS infrastructure using Ansible"
Jump to navigation
Jump to search
↑ https://en.wikiversity.org/wiki/DevOps/Ansible/manage_AWS_infrastructure_using_Ansible
↑ https://docs.ansible.com/ansible/latest/modules/ec2_module.html
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Configuration == | == Configuration == | ||
Configure your computer for use Ansible to manage your Amazon [[AWS]] infrastructure.<ref>https://en.wikiversity.org/wiki/DevOps/Ansible/manage_AWS_infrastructure_using_Ansible</ref> | Configure your computer for use Ansible to manage your Amazon [[AWS]] infrastructure.<ref>https://en.wikiversity.org/wiki/DevOps/Ansible/manage_AWS_infrastructure_using_Ansible</ref> | ||
− | * 1) Install ''aws cli'', ''[[python]]'', ''apt-get install python-pip'' and ''python pip boto'' | + | * 1) Install ''[[aws cli]]'', ''[[python]]'', ''apt-get install python-pip'' and ''python pip boto'' |
* 2) Install [[Ansible]], macOS: <code>brew install ansible</code> | * 2) Install [[Ansible]], macOS: <code>brew install ansible</code> | ||
* 3) Configure your local ''aws cli'' installation to allow you to make operation on your AWS infrastructure. | * 3) Configure your local ''aws cli'' installation to allow you to make operation on your AWS infrastructure. | ||
− | Installation one line: <code>apt-get install awscli python-pip ansible && pip install boto</code> | + | Installation one line: <code>apt-get install awscli python-pip ansible && pip install [[boto]]</code> |
== Basic Operations == | == Basic Operations == | ||
Line 51: | Line 51: | ||
- debug: msg="{{ ec2_facts }}" | - debug: msg="{{ ec2_facts }}" | ||
</pre> | </pre> | ||
+ | |||
+ | |||
+ | == Related terms == | ||
+ | * [[Create aws ec2 instance with ansible]] | ||
== See also == | == See also == | ||
− | * List of Debian9 Image Id (ami): https://wiki.debian.org/Cloud/AmazonEC2Image/Stretch | + | * List of [[Debian9]] Image Id ([[ami]]): https://wiki.debian.org/Cloud/AmazonEC2Image/Stretch |
* List of Ubuntu Image Id (ami): https://cloud-images.ubuntu.com/locator/ec2/ | * List of Ubuntu Image Id (ami): https://cloud-images.ubuntu.com/locator/ec2/ | ||
− | * [[ | + | * [[AWS Command Line Tool (CLI)]] |
* {{Ansible}} | * {{Ansible}} | ||
* Ansible EC2 module documentation https://docs.ansible.com/ansible/2.6/modules/ec2_module.html | * Ansible EC2 module documentation https://docs.ansible.com/ansible/2.6/modules/ec2_module.html | ||
Line 61: | Line 65: | ||
[[Category:Server administration]] | [[Category:Server administration]] | ||
− |
Latest revision as of 12:37, 5 August 2021
Configuration[edit]
Configure your computer for use Ansible to manage your Amazon AWS infrastructure.[1]
- 1) Install aws cli, python, apt-get install python-pip and python pip boto
- 2) Install Ansible, macOS:
brew install ansible
- 3) Configure your local aws cli installation to allow you to make operation on your AWS infrastructure.
Installation one line: apt-get install awscli python-pip ansible && pip install boto
Basic Operations[edit]
- Start a AWS EC2 machine:
We will use ansible EC2 module[2]. Create a new file, for example aws_start_machine.yml
. Put your instance_ids and region values, (execute aws ec2 describe-instances
to obtain them or aws ec2 describe-instances | grep InstanceId
to obtain only InstanceIds) and execute your newly created script,
chmod +x aws_start_machine.yml; ./aws_start_machine.yml
Example. Start and already created EC2 instance. aws_start_ec2server.yml
file:
- (Remember just to use spaces and not tabulator for your YML file)
#!/usr/bin/env ansible-playbook - name: Starting AWS machine hosts: localhost gather_facts: false connection: local vars: instance_ids: - 'i-09999999999' # you will have to modify this line with the InstanceId of your server region: us-east-2 # you will have to change this line to region where your machine was created tasks: - name: Starting AWS Machine. It Will take some time. ec2: instance_ids: '{{ instance_ids }}' region: '{{ region }}' state: running wait: True
Getting information from a AWS machine:
Example aws_status_ec2server.yml
file:
#!/usr/bin/env ansible-playbook - name: Status ec2 instance hosts: localhost connection: local tasks: - ec2_instance_facts: instance_ids: - i-0bd3xx999999999 register: ec2_facts - debug: msg="{{ ec2_facts }}"
Related terms[edit]
See also[edit]
- List of Debian9 Image Id (ami): https://wiki.debian.org/Cloud/AmazonEC2Image/Stretch
- List of Ubuntu Image Id (ami): https://cloud-images.ubuntu.com/locator/ec2/
- AWS Command Line Tool (CLI)
- Ansible: modules, plugins, Playbooks (examples)
ansible-playbook
,ansible-vault
,ansible-inventory
,ansible-config
, Ansible Tower, Ansible Galaxy (Roles) (ansible-galaxy
),ansible-cmdb
,gather facts
,ansible.cfg
,Ansible Molecule
, Ansible collections,register
,template
,--ask-pass
,--ask-become-pass
,remote_user:
,/etc/ansible/hosts
,ansible-doc
,ansible-lint
,.ansible/
,--forks
,--start-at-task
,changelog
,inventory
,Notify:
,ansible HOSTNAME -m ping
,gathering
,/usr/bin/ansible
,ansible -m ping
,ansible.builtin
,hosts: (Ansible)
,set fact:
,when:
,blockinfile:
,become method:
,include:
,git:
, AWX,ansible --help
, Tags, Ansible variables, versions - Ansible EC2 module documentation https://docs.ansible.com/ansible/2.6/modules/ec2_module.html
- Ansible Cloud modules https://docs.ansible.com/ansible/2.6/modules/list_of_cloud_modules.html
Advertising: