Skip to content

Instantly share code, notes, and snippets.

View parberge's full-sized avatar
🤓

Pär Berge parberge

🤓
View GitHub Profile
@parberge
parberge / python
Created October 18, 2017 08:52
dynamic inventory snip
inventory = {
'all': {'hosts': []},
'baseline': {'hosts': []},
'signed_off': {'hosts': []},
'application_installation': {'hosts': []},
'operational_check': {'hosts': []},
'ansible': {'hosts': []},
'_meta': {'hostvars': {}},
}
@parberge
parberge / yaml
Created February 15, 2017 07:47
vars_prompt
---
- hosts: all
vars_prompt:
- name: "reboot_check"
prompt: "Should the host(s) really be rebooted?"
default: "no"
private: no
tasks:
- include: tasks/os/common/reboot.yml
inventory/
├── customer
│   └── group_vars
└── nit
├── group_vars
└── host_vars
@parberge
parberge / gist:83c6fa21625b4acbdb797bc40a8a68be
Last active February 14, 2017 08:54
ansible lookup(dig)
task:
- name: "Check DNS records for host"
set_fact:
dns_a_record: "{{ lookup('dig', ansible_fqdn) }}"
dns_ptr_record: "{{ lookup('dig', ansible_default_ipv4['address'] + '/PTR') }}"
output:
TASK [core : Check DNS records for host] ***************************************
@parberge
parberge / yaml
Created January 25, 2017 09:13
task with conditional that fails
- name: "users | Creating local user(s)"
user:
name: "{{ item }}"
password: "{{ def_local_user_password }}"
state: present
update_password: on_create
when: local_users_extra is defined
with_items: '{{ local_users_extra }}'
tags: "local_users"
- name: "Setting a fact"
set_fact:
spam: True
when: your_condition is True
$ ansible --version
ansible 2.1.2.0
[..]
$ head -n1 inventory
test-host ansible_host=127.0.0.1 test_var=1
$ ansible -m debug -a "var=test_var" -i inventory test-host
test-host | SUCCESS => {
"test_var": 1
}