import files

This commit is contained in:
Yann Autissier
2021-02-09 17:05:00 +01:00
parent f5c4576411
commit 44a6d37ba5
425 changed files with 23195 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
;
[subrepo]
remote = ssh://git@github.com/1001Pharmacies/ansible-aws-cli
branch = master
commit = f10e38af3a9b36648576f9850e0d09fcc7a057df
parent = 9ee8bfab9d2f5e5591c2e8a3d6f3a03b56b36196
method = merge
cmdver = 0.4.0
+35
View File
@@ -0,0 +1,35 @@
# DEPRECATION NOTICE
We have moved away from Ansible and are in the process of removing or transferring ownership of our Ansible repositories. If you rely on this repository directly, please make arrangements to replace this dependency with your own fork.
# AWS CLI role for Ansible
Installs and configures the AWS CLI for conveniently interacting with AWS services such as S3.
## Requirements
- Tested on Ubuntu 12.04 Server;
- Ansible 2.0+
## Role Variables
The default variables are as follows:
aws_output_format: 'json'
aws_region: 'ap-southeast-2'
aws_access_key_id: 'YOUR_ACCESS_KEY_ID'
aws_secret_access_key: 'YOUR_SECRET_ACCESS_KEY'
## Example Playbook
- hosts: 'servers'
roles:
- role: 'dstil.aws-cli'
aws_output_format: 'json'
aws_region: 'ap-southeast-2'
aws_access_key_id: 'SUPER_SECRET_ACCESS_KEY_ID' # Don't version this or put it on pastebin
aws_secret_access_key: 'SUPER_SECRET_ACCESS_KEY' # Ditto
# License
This playbook is provided 'as-is' under the conditions of the BSD license. No fitness for purpose is guaranteed or implied.
+7
View File
@@ -0,0 +1,7 @@
---
aws_cli_user: "{{ ansible_user|default('root') }}"
aws_cli_group: "{{ ansible_user|default('root') }}"
aws_output_format: 'json'
aws_region: 'eu-west-1'
aws_access_key_id: 'YOUR_ACCESS_KEY_ID'
aws_secret_access_key: 'YOUR_SECRET_ACCESS_KEY'
+14
View File
@@ -0,0 +1,14 @@
---
galaxy_info:
author: 'Rohan Liston'
description: 'Installs and configures the AWS CLI for conveniently interacting with AWS services such as S3.'
company: 'DSTIL'
license: 'BSD'
min_ansible_version: 2.0
platforms:
- name: 'Ubuntu'
versions:
- 'precise'
categories:
- 'development'
dependencies: []
+144
View File
@@ -0,0 +1,144 @@
---
- name: 'Install AWS CLI'
tags: 'aws-cli'
become: 'yes'
pip: >
executable=pip
name=awscli
state=present
extra_args=--no-cache-dir
- name: 'Install docker python'
tags: 'aws-cli'
become: 'yes'
pip: >
name=docker
state=present
extra_args=--no-cache-dir
- name: 'Install boto python'
tags: 'aws-cli'
become: 'yes'
pip: >
name=boto3
state=present
extra_args=--no-cache-dir
- name: Set home directory of the user
set_fact:
home_dir: /home/{{ aws_cli_user }}
when: "not aws_cli_user == 'root'"
- name: Set home directory for root
set_fact:
home_dir: /root
when: "aws_cli_user == 'root'"
- name: 'Create the AWS config directory'
tags: 'aws-cli'
become: 'yes'
file: >
path={{ home_dir }}/.aws
state=directory
owner={{ aws_cli_user }}
group={{ aws_cli_group }}
mode=0755
- name: 'Copy AWS CLI config'
tags: 'aws-cli'
become: 'yes'
template: >
src=aws_cli_config.j2
dest={{ home_dir }}/.aws/config
owner={{ aws_cli_user }}
group={{ aws_cli_group }}
mode=0600
force=yes
- name: 'Copy AWS CLI credentials'
tags: 'aws-cli'
become: 'yes'
template: >
src=aws_cli_credentials.j2
dest={{ home_dir }}/.aws/credentials
owner={{ aws_cli_user }}
group={{ aws_cli_group }}
mode=0600
force=yes
- name: aws - check AWS meta-data URI
uri:
url: http://169.254.169.254/latest/meta-data
timeout: 1
register: aws_uri_check
tags: 'aws'
failed_when: False
- name: aws - get instance metadata
tags: 'aws'
ec2_metadata_facts:
when: aws_uri_check.status == 200
- name: aws - get instance tags
tags: 'aws'
ec2_tag:
aws_access_key: "{{ aws_access_key_id }}"
aws_secret_key: "{{ aws_secret_access_key }}"
region: "{{ ansible_ec2_placement_region }}"
resource: "{{ ansible_ec2_instance_id }}"
state: list
register: ec2_tags
when: ansible_ec2_instance_id is defined
- name: aws - set hostname
hostname: name="{{ ec2_tags.tags.hostname }}{% if ec2_tags.tags.domainname is defined %}.{{ ec2_tags.tags.domainname }}{% endif %}"
tags: 'aws'
when: ec2_tags.tags is defined and ec2_tags.tags.hostname is defined
- name: aws - ecr login
shell: "$(aws ecr get-login --no-include-email --region {{ aws_region }})"
tags: 'aws'
when: ec2_tags.tags is defined
- name: aws - prune docker objects (including non-dangling images)
docker_prune:
containers: yes
images: yes
images_filters:
dangling: false
networks: yes
volumes: yes
builder_cache: yes
tags: 'aws'
- name: aws - launch docker containers
docker_container:
image: "{{docker_registry|default(ec2_tags.tags.user)}}/{{ec2_tags.tags.user}}/{{ec2_tags.tags.env}}/{% if ':' in item %}{{item}}{% else %}{{item}}:{{docker_image_tag|default('latest')}}{% endif %}"
name: "{{ec2_tags.tags.user}}_{{ec2_tags.tags.env}}_{{item|replace('/','_')|regex_replace(':.*','')}}"
network_mode: host
pull: yes
restart_policy: always
volumes:
- "{{ lookup('env','ANSIBLE_DISKS_NFS_PATH') }}:/shared"
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
tags: 'aws'
with_items: '{{ec2_tags.tags.services.split(" ")}}'
when: ec2_tags.tags is defined and ec2_tags.tags.env is defined and ec2_tags.tags.services is defined and ec2_tags.tags.user is defined
- name: aws - add docker containers to inventory
add_host:
name: "{{ec2_tags.tags.user}}_{{ec2_tags.tags.env}}_{{item|replace('/','_')|regex_replace(':.*','')}}"
ansible_connection: docker
changed_when: false
tags: 'aws'
with_items: '{{ec2_tags.tags.services.split(" ")}}'
when: ec2_tags.tags is defined and ec2_tags.tags.env is defined and ec2_tags.tags.services is defined and ec2_tags.tags.user is defined
- name: aws - run make deploy in docker containers
delegate_to: "{{ec2_tags.tags.user}}_{{ec2_tags.tags.env}}_{{item|replace('/','_')|regex_replace(':.*','')}}"
raw: "command -v make || exit 0 && make deploy CONTAINER={{ec2_tags.tags.user}}_{{ec2_tags.tags.env}}_{{item|replace('/','_')|regex_replace(':.*','')}} HOST={{ansible_ec2_local_ipv4}}"
tags: 'aws'
with_items: '{{ec2_tags.tags.services.split(" ")}}'
when: ec2_tags.tags is defined and ec2_tags.tags.env is defined and ec2_tags.tags.services is defined and ec2_tags.tags.user is defined
@@ -0,0 +1,7 @@
[default]
{% if aws_output_format|length %}
output = {{ aws_output_format }}
{% endif %}
{% if aws_region|length %}
region = {{ aws_region }}
{% endif %}
@@ -0,0 +1,5 @@
{% if aws_access_key_id|length and aws_secret_access_key|length %}
[default]
aws_access_key_id = {{ aws_access_key_id }}
aws_secret_access_key = {{ aws_secret_access_key }}
{% endif %}