Hi Group,
I am trying to add some basic facts to a system but nothing seems to work.
My goal is to add a simple fact like the type of the server and the main application running on it to be set
Type of server can be webserver (apache/tomcat)/ database server (mysql/postgress .. etc)
And I would like to do this from the commandline with -e at initial deployment of a server.
My main.yml looks like this
__________________________________________________________________________
---
# Task to set facts on system, based on commandline variables
- name: Set system facts
action: set_fact system_type={{system_type}}
action: set_fact main_app={{main_app}}
_________________________________________________________________________
and the result =
TASK: [system-config | Set system facts] **************************************
ok: [my-targeted-machine]
____________________________________________________________________________
---
# Task to set facts on system, based on commandline variables
- name: Set system facts
set_fact: system_type="{{system_type}}" main_app="{{main_app}}"
____________________________________________________________________________
Has the same result
ok: [my-targeted-machine]
Or
____________________________________________________________________________
---
# Task to set facts on system, based on commandline variables
- name: Set system facts
- set_fact: system_type="{{system_type}}" main_app="{{main_app}}"
____________________________________________________________________________
Has this result : ERROR: 'action' or 'local_action' attribute missing in task "Set system facts"
And when removing the -name: Set system facts line I can see my variables are used from the commandline :-)
$ ansible-playbook -i 'mytargeted-machine,' all.yml --extra-vars '{"system_type":"webservert","main_app":"apache2"}'
TASK: [system-config | set_fact system_type="webservert" main_app="apache2"] ***
ok: [my-targeted-machine]
So what would be the best approach to set a fact ??
.
Ultimate goal: use fact caching and targeting machines with specific facts !