Skip to content

Instantly share code, notes, and snippets.

---
- hosts: localhost
connection: local
tasks:
- name: create a vpc
ec2_vpc_net:
name: ansible-test-vpc
cidr_block: 10.10.0.0/16
profile: "{{ profile }}"
region: us-east-1
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: create routing rules
ec2_vpc_route_table:
profile: shertel
vpc_id: "{{ vpc_id }}"
region: us-east-1
@s-hertel
s-hertel / test.yml
Last active November 1, 2017 13:28
tasks:
- name: add two tags to a resource
ec2_tag:
state: present
resource: “{{ id }}”
tags:
foo: bar
name: test
#- name: this should remove the foo bar tag
@s-hertel
s-hertel / ec2_tag
Created November 7, 2017 15:20
remove tags by key only
+++ b/lib/ansible/modules/cloud/amazon/ec2_tag.py
@@ -33,6 +33,10 @@ options:
default: present
choices: ['present', 'absent', 'list']
aliases: []
+ remove_by_tag_key_only:
+ description:
+ - a boolean to indicate whether to remove tags with matching keys
+ default: False
tags:
---
- hosts: amazon_host
gather_facts: yes
tasks:
- name: create target files
file:
state: touch
path: "{{ item }}"
loop: ['/tmp/onlyonremote.txt', '/tmp/existseverywhere.txt']
@s-hertel
s-hertel / main.yml
Created June 29, 2018 12:46
playbook to run a role called manage_s3
# structure:
playbook.yml # Yaml file to run
roles # A directory
manage_s3 # A directory for the role named manage_s3
tasks # A directory
main.yml # The place where the role starts
# can have other playbooks to include in main.yml here
# Can also have a directory for vars, files, templates, etc: see https://docs.ansible.com/ansible/2.5/user_guide/playbooks_reuse_roles.html
# Can also have other roles here
@s-hertel
s-hertel / gist:6b591edfbd80a8e744eb93c186fd4a45
Last active July 12, 2018 16:53
ec2 contrib script - patch to assume the same role multiple times for different regions and services
diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py
index 479bdf1e4e..e31265d941 100755
--- a/contrib/inventory/ec2.py
+++ b/contrib/inventory/ec2.py
@@ -247,6 +247,9 @@ class Ec2Inventory(object):
def __init__(self):
''' Main execution path '''
+ # To allow using STS credentials for the connections to different services/regions, indicate when a role has already been assumed
+ self.assumed_role = False
@s-hertel
s-hertel / output
Created August 17, 2018 20:02
possible diff mode output
(python2.7.13) MacBook-Pro-44:ansible shertel$ ansible-playbook test_ec2_group_diff_mode.yml -vvvvv
ansible-playbook 2.7.0.dev0 (pr/37212 d67a5c00ab) last updated 2018/08/17 15:54:55 (GMT -400)
config file = None
configured module search path = [u'/Users/shertel/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /Users/shertel/Workspace/ansible_4/ansible/lib/ansible
executable location = /Users/shertel/Workspace/ansible_4/ansible/bin/ansible-playbook
python version = 2.7.13 (default, Sep 22 2017, 10:31:19) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
No config file found; using defaults
setting up inventory plugins
Parsed /etc/ansible/hosts inventory source with ini plugin
elb_target_group: https://github.com/ansible/ansible/pull/45169
ecs_taskdefinition: https://github.com/ansible/ansible/pull/44942
lambda_policy: https://github.com/ansible/ansible/pull/44871
ec2_metadata_facts: https://github.com/ansible/ansible/pull/43394
elb_target_group: https://github.com/ansible/ansible/pull/43247
aws_application_scaling_policy: https://github.com/ansible/ansible/pull/43042
ec2_group: https://github.com/ansible/ansible/pull/42765
@s-hertel
s-hertel / DO output
Created December 3, 2018 16:51
Test Digital Ocean with s3_bucket and aws_s3
(python2.7.13) 11:47:47 [ansible]$ ansible-playbook test_do_s3_bucket.yml -v
No config file found; using defaults
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] ***************************************************************************************************************************************************************************************
TASK [Create DO bucket] ********************************************************************************************************************************************************************************
changed: [localhost] => {"changed": true, "name": "testdo", "policy": null, "requester_pays": false, "tags": {}, "versioning": {"MfaDelete": "Disabled", "Versioning": "Disabled"}}