Documente Academic
Documente Profesional
Documente Cultură
<----. __ / __ \
* ^Subject:.*500 report <----|====O)))==) \) /====
<----' `--' `.__,' \
|ansible-playbook ~/plays/report.yml |
\
|
/
______( (_ / \______
,' ,-----' | \
`--{__________) \/
--- #report.yml
…
- shell: "awk '{print \$9}' …
register: report
- mail: to={{lookup(‘env’,’FROM’)}} body={{report}} …
#UTIL>small_scripts
● tries not to be a programming language
● but … sometimes its very useful as such
● plays can wrap existing roles/task lists
● vars_prompt/pause allow for interactivity
● -e “var=val” for completely batch
● -e @file.json: you can use json data files
#UTIL>/sbin/departed
#!/usr/bin/ansible-playbook
---
- name: Ensure only valid users
hosts: all
gather_facts: False
sudo: True
vars_files:
#departed: [ alan, bcoca, isaac, mathew, willy ]
- /etc/departed_users.yml
tasks:
- name: Delete departed user and all it’s files
user: name={{item}} state=absent remove=yes
with_items: “{{departed}}”
#UTIL>/bin/release_apps
#!/usr/bin/ansible-playbook
- hosts: localhost
vars_prompt: ______________________
- name: app_name
prompt: “Which app do you want to deploy?” / for reusability, use \
- name: app_version \ includes and roles /
prompt: “Choose version/tag (default HEAD)”
default: ‘HEAD’
----------------------
\
tasks: \ __
- git: repo=git@myreposerver/{{app_version}} version={{app_version}} ...
...
UooU\.'@@@@@@`.
\__/(@@@@@@@@@@)
- hosts: app_servers (@@@@@@@@)
serial: 1
tasks: `YY~~~~YY'
- pause: "are you sure you want to stop all services?"
|| ||
- mail: body=“{{removed}}”
#HACK>ansible_events
syslog_json callback plugin
def __init__(self):
self.logger = logging.getLogger('ansible logger')
self.logger.setLevel(logging.DEBUG)
self.handler = logging.handlers.SysLogHandler(
address = (os.getenv('SYSLOG_SERVER','locahost'),
os.getenv('SYSLOG_PORT',514)),
facility=logging.handlers.SysLogHandler.LOG_USER
)
self.logger.addHandler(handler)
....
def runner_on_ok(self, host, res):
self.logger.info('RUNNER_ON_OK ' + host + ' ' \
+ json.dumps(res, sort_keys=True))
\
\
,;;;;;;;,
def say(msg, voice): ;;;;;;;;;;;,
;;;;;'_____;'
subprocess.call([SAY_CMD, msg, "--voice=%s" % (voice)]) ;;;(/))))|((\
_;;((((((|))))
/ |_\\\\\\\\\\\\
.--~( \ ~))))))))))))
def __init__(self): / \ `\-(((((((((((\\
| | `\ ) |\ /|)
# plugin disable itself if say is not present | | `. _/ \_____/ |
if not os.path.exists(SAY_CMD): | , `\~ /
| \ \ /
self.disabled = True | `. `\| /
print "%s does not exist, plugin %s disabled" % |\ ~- `\
\____~._/~ -_,
/
(\
(SAY_CMD, os.path.basename(__file__)) |-----|\ \ ';;
| | :;;;' \
… | / | |
| | |
- <module name>:
- template:
src: “{{apache_config}}.j2”
dest: /etc/{{apache_config}}
owner: “{{apache_user}}”
group: “{{apache_group}}”
notify: “apache_restart”
#HACK>abstract package
Redhat.yml
---
apache_user: httpd
apache_group: httpd
apache_config: /etc/httpd/conf/httpd.conf
apache_pkgs:
- httpd
- mod_ssl
- php-fpm
apache_service: httpd
#HACK>abstract package
__________________
Debian.yml / can break \
\ apachectl utils /
------------------
\
\
--- .--.
apache_user: www-data |o_o |
|:_/ |
apache_group: www-data // \ \
(| | )
apache_config: /etc/apache2/httpd.conf /'\_ _/`\
\___)=(___/
apache_pkgs:
- apache2-mpm
- libapache2-mod-ssl
- php5-fpm
apache_service: apache2
#THE END>wait 6 && exit
● Ansible was born to play well with Unix
● Roles allow for reuse and sharing __________
< goodbye! >
----------
\ ^__^