1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Native YAML - Web infrastructure (#3594)

* Native YAML

* YAML for jira as well

* Native YAML for Jboss

* Fix missing spaces
This commit is contained in:
Fabio Alessandro Locati 2016-12-01 13:58:22 +00:00 committed by Matt Clay
parent 367a0c5d99
commit 5209969a7c
5 changed files with 202 additions and 85 deletions

View file

@ -71,21 +71,41 @@ options:
EXAMPLES = ''' EXAMPLES = '''
# Get all current balancer pool members' attributes: # Get all current balancer pool members' attributes:
- apache2_mod_proxy: balancer_vhost=10.0.0.2 - apache2_mod_proxy:
balancer_vhost: 10.0.0.2
# Get a specific member's attributes: # Get a specific member's attributes:
- apache2_mod_proxy: balancer_vhost=myws.mydomain.org balancer_suffix="/lb/" member_host=node1.myws.mydomain.org - apache2_mod_proxy:
balancer_vhost: myws.mydomain.org
balancer_suffix: /lb/
member_host: node1.myws.mydomain.org
# Enable all balancer pool members: # Enable all balancer pool members:
- apache2_mod_proxy: balancer_vhost="{{ myloadbalancer_host }}" - apache2_mod_proxy:
balancer_vhost: '{{ myloadbalancer_host }}'
register: result register: result
- apache2_mod_proxy: balancer_vhost="{{ myloadbalancer_host }}" member_host="{{ item.host }}" state=present - apache2_mod_proxy:
with_items: "{{ result.members }}" balancer_vhost: '{{ myloadbalancer_host }}'
member_host: '{{ item.host }}'
state: present
with_items: '{{ result.members }}'
# Gracefully disable a member from a loadbalancer node: # Gracefully disable a member from a loadbalancer node:
- apache2_mod_proxy: balancer_vhost="{{ vhost_host }}" member_host="{{ member.host }}" state=drained delegate_to=myloadbalancernode - apache2_mod_proxy:
- wait_for: host="{{ member.host }}" port={{ member.port }} state=drained delegate_to=myloadbalancernode balancer_vhost: '{{ vhost_host }}'
- apache2_mod_proxy: balancer_vhost="{{ vhost_host }}" member_host="{{ member.host }}" state=absent delegate_to=myloadbalancernode member_host: '{{ member.host }}'
state: drained
delegate_to: myloadbalancernode
- wait_for:
host: '{{ member.host }}'
port: '{{ member.port }}'
state: drained
delegate_to: myloadbalancernode
- apache2_mod_proxy:
balancer_vhost: '{{ vhost_host }}'
member_host: '{{ member.host }}'
state: absent
delegate_to: myloadbalancernode
''' '''
RETURN = ''' RETURN = '''

View file

@ -163,69 +163,121 @@ procedure to remove it during cleanup.
# Typical usage: # Typical usage:
- name: Initialize the deploy root and gather facts - name: Initialize the deploy root and gather facts
deploy_helper: path=/path/to/root deploy_helper:
path: /path/to/root
- name: Clone the project to the new release folder - name: Clone the project to the new release folder
git: repo=git://foosball.example.org/path/to/repo.git dest={{ deploy_helper.new_release_path }} version=v1.1.1 git:
repo: 'git://foosball.example.org/path/to/repo.git'
dest: '{{ deploy_helper.new_release_path }}'
version: 'v1.1.1'
- name: Add an unfinished file, to allow cleanup on successful finalize - name: Add an unfinished file, to allow cleanup on successful finalize
file: path={{ deploy_helper.new_release_path }}/{{ deploy_helper.unfinished_filename }} state=touch file:
path: '{{ deploy_helper.new_release_path }}/{{ deploy_helper.unfinished_filename }}'
state: touch
- name: Perform some build steps, like running your dependency manager for example - name: Perform some build steps, like running your dependency manager for example
composer: command=install working_dir={{ deploy_helper.new_release_path }} composer:
command: install
working_dir: '{{ deploy_helper.new_release_path }}'
- name: Create some folders in the shared folder - name: Create some folders in the shared folder
file: path='{{ deploy_helper.shared_path }}/{{ item }}' state=directory file:
with_items: ['sessions', 'uploads'] path: '{{ deploy_helper.shared_path }}/{{ item }}'
- name: Add symlinks from the new release to the shared folder state: directory
file: path='{{ deploy_helper.new_release_path }}/{{ item.path }}'
src='{{ deploy_helper.shared_path }}/{{ item.src }}'
state=link
with_items: with_items:
- { path: "app/sessions", src: "sessions" } - sessions
- { path: "web/uploads", src: "uploads" } - uploads
- name: Add symlinks from the new release to the shared folder
file:
path: '{{ deploy_helper.new_release_path }}/{{ item.path }}'
src: '{{ deploy_helper.shared_path }}/{{ item.src }}'
state: link
with_items:
- path: app/sessions
src: sessions
- path: web/uploads
src: uploads
- name: Finalize the deploy, removing the unfinished file and switching the symlink - name: Finalize the deploy, removing the unfinished file and switching the symlink
deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=finalize deploy_helper:
path: /path/to/root
release: '{{ deploy_helper.new_release }}'
state: finalize
# Retrieving facts before running a deploy # Retrieving facts before running a deploy
- name: Run 'state=query' to gather facts without changing anything - name: Run 'state=query' to gather facts without changing anything
deploy_helper: path=/path/to/root state=query deploy_helper:
path: /path/to/root
state: query
# Remember to set the 'release' parameter when you actually call 'state=present' later # Remember to set the 'release' parameter when you actually call 'state=present' later
- name: Initialize the deploy root - name: Initialize the deploy root
deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=present deploy_helper:
path: /path/to/root
release: '{{ deploy_helper.new_release }}'
state: present
# all paths can be absolute or relative (to the 'path' parameter) # all paths can be absolute or relative (to the 'path' parameter)
- deploy_helper: path=/path/to/root - deploy_helper:
releases_path=/var/www/project/releases path: /path/to/root
shared_path=/var/www/shared releases_path: /var/www/project/releases
current_path=/var/www/active shared_path: /var/www/shared
current_path: /var/www/active
# Using your own naming strategy for releases (a version tag in this case): # Using your own naming strategy for releases (a version tag in this case):
- deploy_helper: path=/path/to/root release=v1.1.1 state=present - deploy_helper:
- deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=finalize path: /path/to/root
release: 'v1.1.1'
state: present
- deploy_helper:
path: /path/to/root
release: '{{ deploy_helper.new_release }}'
state: finalize
# Using a different unfinished_filename: # Using a different unfinished_filename:
- deploy_helper: path=/path/to/root - deploy_helper:
unfinished_filename=README.md path: /path/to/root
release={{ deploy_helper.new_release }} unfinished_filename: README.md
state=finalize release: '{{ deploy_helper.new_release }}'
state: finalize
# Postponing the cleanup of older builds: # Postponing the cleanup of older builds:
- deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=finalize clean=False - deploy_helper:
- deploy_helper: path=/path/to/root state=clean path: /path/to/root
release: '{{ deploy_helper.new_release }}'
state: finalize
clean: False
- deploy_helper:
path: /path/to/root
state: clean
# Or running the cleanup ahead of the new deploy # Or running the cleanup ahead of the new deploy
- deploy_helper: path=/path/to/root state=clean - deploy_helper:
- deploy_helper: path=/path/to/root state=present path: /path/to/root
state: clean
- deploy_helper:
path: /path/to/root
state: present
# Keeping more old releases: # Keeping more old releases:
- deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=finalize keep_releases=10 - deploy_helper:
path: /path/to/root
release: '{{ deploy_helper.new_release }}'
state: finalize
keep_releases: 10
# Or, if you use 'clean=false' on finalize: # Or, if you use 'clean=false' on finalize:
- deploy_helper: path=/path/to/root state=clean keep_releases=10 - deploy_helper:
path: /path/to/root
state: clean
keep_releases: 10
# Removing the entire project root folder # Removing the entire project root folder
- deploy_helper: path=/path/to/root state=absent - deploy_helper:
path: /path/to/root
state: absent
# Debugging the facts returned by the module # Debugging the facts returned by the module
- deploy_helper: path=/path/to/root - deploy_helper:
- debug: var=deploy_helper path: /path/to/root
- debug:
var: deploy_helper
''' '''
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.pycompat24 import get_exception

View file

@ -59,14 +59,19 @@ notes:
EXAMPLES = ''' EXAMPLES = '''
Example playbook entries using the ejabberd_user module to manage users state. Example playbook entries using the ejabberd_user module to manage users state.
tasks: - name: create a user if it does not exists
ejabberd_user:
username: test
host: server
password: password
- name: create a user if it does not exists - name: delete a user if it exists
action: ejabberd_user username=test host=server password=password ejabberd_user:
username: test
- name: delete a user if it exists host: server
action: ejabberd_user username=test host=server state=absent state: absent
''' '''
import syslog import syslog
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.basic import * from ansible.module_utils.basic import *

View file

@ -52,11 +52,21 @@ author: "Jeroen Hoekx (@jhoekx)"
EXAMPLES = """ EXAMPLES = """
# Deploy a hello world application # Deploy a hello world application
- jboss: src=/tmp/hello-1.0-SNAPSHOT.war deployment=hello.war state=present - jboss:
src: /tmp/hello-1.0-SNAPSHOT.war
deployment: hello.war
state: present
# Update the hello world application # Update the hello world application
- jboss: src=/tmp/hello-1.1-SNAPSHOT.war deployment=hello.war state=present - jboss:
src: /tmp/hello-1.1-SNAPSHOT.war
deployment: hello.war
state: present
# Undeploy the hello world application # Undeploy the hello world application
- jboss: deployment=hello.war state=absent - jboss:
deployment: hello.war
state: absent
""" """
import os import os

View file

@ -105,59 +105,89 @@ author: "Steve Smith (@tarka)"
EXAMPLES = """ EXAMPLES = """
# Create a new issue and add a comment to it: # Create a new issue and add a comment to it:
- name: Create an issue - name: Create an issue
jira: uri={{server}} username={{user}} password={{pass}} jira:
project=ANS operation=create uri: '{{ server }}'
summary="Example Issue" description="Created using Ansible" issuetype=Task username: '{{ user }}'
password: '{{ pass }}'
project: ANS
operation: create
summary: Example Issue
description: Created using Ansible
issuetype: Task
register: issue register: issue
- name: Comment on issue - name: Comment on issue
jira: uri={{server}} username={{user}} password={{pass}} jira:
issue={{issue.meta.key}} operation=comment uri: '{{ server }}'
comment="A comment added by Ansible" username: '{{ user }}'
password: '{{ pass }}'
issue: '{{ issue.meta.key }}'
operation: comment
comment: A comment added by Ansible
# Assign an existing issue using edit # Assign an existing issue using edit
- name: Assign an issue using free-form fields - name: Assign an issue using free-form fields
jira: uri={{server}} username={{user}} password={{pass}} jira:
issue={{issue.meta.key}} operation=edit uri: '{{ server }}'
assignee=ssmith username: '{{ user }}'
password: '{{ pass }}'
issue: '{{ issue.meta.key}}'
operation: edit
assignee: ssmith
# Create an issue with an existing assignee # Create an issue with an existing assignee
- name: Create an assigned issue - name: Create an assigned issue
jira: uri={{server}} username={{user}} password={{pass}} jira:
project=ANS operation=create uri: '{{ server }}'
summary="Assigned issue" description="Created and assigned using Ansible" username: '{{ user }}'
issuetype=Task assignee=ssmith password: '{{ pass }}'
project: ANS
operation: create
summary: Assigned issue
description: Created and assigned using Ansible
issuetype: Task
assignee: ssmith
# Edit an issue using free-form fields # Edit an issue
- name: Set the labels on an issue using free-form fields - name: Set the labels on an issue using free-form fields
jira: uri={{server}} username={{user}} password={{pass}} jira:
issue={{issue.meta.key}} operation=edit uri: '{{ server }}'
args: { fields: {labels: ["autocreated", "ansible"]}} username: '{{ user }}'
password: '{{ pass }}'
- name: Set the labels on an issue, YAML version issue: '{{ issue.meta.key }}'
jira: uri={{server}} username={{user}} password={{pass}} operation: edit
issue={{issue.meta.key}} operation=edit args:
args: fields:
fields: labels:
labels: - autocreated
- "autocreated" - ansible
- "ansible"
- "yaml"
# Retrieve metadata for an issue and use it to create an account # Retrieve metadata for an issue and use it to create an account
- name: Get an issue - name: Get an issue
jira: uri={{server}} username={{user}} password={{pass}} jira:
project=ANS operation=fetch issue="ANS-63" uri: '{{ server }}'
username: '{{ user }}'
password: '{{ pass }}'
project: ANS
operation: fetch
issue: ANS-63
register: issue register: issue
- name: Create a unix account for the reporter - name: Create a unix account for the reporter
sudo: true become: true
user: name="{{issue.meta.fields.creator.name}}" comment="{{issue.meta.fields.creator.displayName}}" user:
name: '{{ issue.meta.fields.creator.name }}'
comment: '{{issue.meta.fields.creator.displayName }}'
# Transition an issue by target status # Transition an issue by target status
- name: Close the issue - name: Close the issue
jira: uri={{server}} username={{user}} password={{pass}} jira:
issue={{issue.meta.key}} operation=transition status="Done" uri: '{{ server }}'
username: '{{ user }}'
password: '{{ pass }}'
issue: '{{ issue.meta.key }}'
operation: transition
status: Done
""" """
try: try: