Created
March 10, 2015 13:52
-
-
Save djoreilly/86e233f225f2c63d633a to your computer and use it in GitHub Desktop.
howto augment ansible facts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://jpmens.net/2012/07/15/ansible-it-s-a-fact/ | |
#$ cat count_users | |
##!/bin/sh | |
#COUNT=`who | wc -l` | |
#cat <<EOF | |
#{ | |
# "ansible_facts" : { | |
# "users_logged_in" : $COUNT | |
# } | |
#} | |
#EOF | |
# export ANSIBLE_LIBRARY=<path-to count_users> | |
--- | |
- name: Test augment Ansible facts | |
hosts: | |
- node1 | |
user: vagrant | |
sudo: False | |
gather_facts: True | |
tasks: | |
- action: count_users | |
- debug: msg="the hostname is {{ inventory_hostname }}" | |
- debug: msg="there are {{ users_logged_in }} users logged in" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PLAY [Test augment Ansible facts] *********************************************
GATHERING FACTS ***************************************************************
ok: [node1]
TASK: [count_users] ***********************************************************
ok: [node1] => {"ansible_facts": {"users_logged_in": 3}}
TASK: [debug msg="the hostname is {{ inventory_hostname }}"] ******************
ok: [node1] => {
"msg": "the hostname is node1"
}
TASK: [debug msg="there are {{ users_logged_in }} users logged in"] ***********
ok: [node1] => {
"msg": "there are 3 users logged in"
}
PLAY RECAP ********************************************************************
node1 : ok=4 changed=0 unreachable=0 failed=0