Skip to content

Instantly share code, notes, and snippets.

---
- hosts: all
connection: local
tasks:
- name: run a sample command
command: uptime
register: uptimeOutput
tasks:
- name: install prerequisite packages
apt:
update_cache: yes
name: "{{ item }}"
install_recommends: no
state: latest
with_items:
- nginx
- python-pip
- name: Install Apache
apt: name={{ item }} state=present
with_items:
- apache2-mpm-prefork
- libapache2-mod-php5
Output with --extra-vars "hosts=foo":
Timothys-MacBook-Pro:ansible-test tgerla$ ansible-playbook -i inventory2 test-nulty.py --extra-vars "hosts=foo" -c local
PLAY [foo] ********************************************************************
skipping: no hosts matched
PLAY RECAP ********************************************************************
Output with --extra-vars "hosts= foo":
---
my_dict:
blargh: "{{ registered_foo }}"
blerf: "{{ registered_bar }}"
#!/usr/bin/python
import sys
import os
from ansible.module_utils.basic import *
def main():
facts = {}
module = AnsibleModule(argument_spec={})
{% for host in groups['mygroup'] %}
{% if host != inventory_hostname %}
...something {{host}}
{% endif %}
{% endfor %}
@tgerla
tgerla / app_defaults.py
Last active May 27, 2023 14:44
example lookup plugin for ansible
import ansible.utils as utils
#
# Put this file in lookup_plugins/ alongside your playbooks.
#
# Lookup plugins can be called two ways: via with_ as a task loop
# construct, or via lookup('name').
#
# You can find the code for the basic lookup plugins here:
# v1: https://github.com/ansible/ansible/tree/devel/v1/ansible/runner/lookup_plugins
# v2: https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/lookup
---
myList:
- one
- two
- three
main_datastructure:
myList: "{{ myList }}"
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-add-repository ppa:ansible/ansible
Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.
http://ansible.com/
More info: https://launchpad.net/~ansible/+archive/ubuntu/ansible
Press [ENTER] to continue or ctrl-c to cancel adding it
gpg: keyring `/tmp/tmpyb8hljmx/secring.gpg' created
gpg: keyring `/tmp/tmpyb8hljmx/pubring.gpg' created
gpg: requesting key 7BB9C367 from hkp server keyserver.ubuntu.com