2014-09-26 01:01:01 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-03-15 21:15:24 +00:00
|
|
|
# Copyright: (c) 2013, Dag Wieers (@dagwieers) <dag@wieers.com>
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['stableinterface'],
|
|
|
|
'supported_by': 'core'}
|
|
|
|
|
2016-12-06 10:35:05 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
2018-03-15 21:15:24 +00:00
|
|
|
author:
|
|
|
|
- Dag Wieers (@dagwieers)
|
2014-09-26 01:01:01 +00:00
|
|
|
module: set_fact
|
|
|
|
short_description: Set host facts from a task
|
|
|
|
description:
|
2017-03-23 01:50:28 +00:00
|
|
|
- This module allows setting new variables. Variables are set on a host-by-host basis just like facts discovered by the setup module.
|
2018-11-30 14:42:47 +00:00
|
|
|
- These variables will be available to subsequent plays during an ansible-playbook run.
|
|
|
|
- Set C(cacheable) to C(yes) to save variables across executions
|
|
|
|
using a fact cache. Variables created with set_fact have different precedence depending on whether they are or are not cached.
|
2017-03-23 01:50:28 +00:00
|
|
|
- Per the standard Ansible variable precedence rules, many other types of variables have a higher priority, so this value may be overridden.
|
2018-04-20 16:35:50 +00:00
|
|
|
See L(Variable Precedence Guide,../user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable) for more information.
|
2017-06-26 15:26:53 +00:00
|
|
|
- This module is also supported for Windows targets.
|
2014-09-26 01:01:01 +00:00
|
|
|
options:
|
|
|
|
key_value:
|
|
|
|
description:
|
|
|
|
- The C(set_fact) module takes key=value pairs as variables to set
|
|
|
|
in the playbook scope. Or alternatively, accepts complex arguments
|
|
|
|
using the C(args:) statement.
|
|
|
|
required: true
|
2017-08-02 19:57:58 +00:00
|
|
|
cacheable:
|
|
|
|
description:
|
2018-11-07 16:06:00 +00:00
|
|
|
- This boolean converts the variable into an actual 'fact' which will also be added to the fact cache, if fact caching is enabled.
|
|
|
|
- Normally this module creates 'host level variables' and has much higher precedence, this option changes the nature and precedence
|
|
|
|
(by 7 steps) of the variable created.
|
|
|
|
https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable
|
2018-03-15 21:15:24 +00:00
|
|
|
type: bool
|
|
|
|
default: 'no'
|
2017-08-02 19:57:58 +00:00
|
|
|
version_added: "2.4"
|
2014-09-26 01:01:01 +00:00
|
|
|
version_added: "1.2"
|
2016-07-06 15:14:42 +00:00
|
|
|
notes:
|
|
|
|
- "The `var=value` notation can only create strings or booleans.
|
|
|
|
If you want to create lists/arrays or dictionary/hashes use `var: [val1, val2]`"
|
2017-06-26 15:26:53 +00:00
|
|
|
- This module is also supported for Windows targets.
|
2017-08-02 19:57:58 +00:00
|
|
|
- Since 'cacheable' is now a module param, 'cacheable' is no longer a valid fact name as of 2.4.
|
2014-09-26 01:01:01 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
2016-07-06 15:14:42 +00:00
|
|
|
# Example setting host facts using key=value pairs, note that this always creates strings or booleans
|
2017-02-23 09:15:32 +00:00
|
|
|
- set_fact: one_fact="something" other_fact="{{ local_var }}"
|
2014-09-26 01:01:01 +00:00
|
|
|
|
|
|
|
# Example setting host facts using complex arguments
|
|
|
|
- set_fact:
|
|
|
|
one_fact: something
|
|
|
|
other_fact: "{{ local_var * 2 }}"
|
2015-05-09 20:51:17 +00:00
|
|
|
another_fact: "{{ some_registered_var.results | map(attribute='ansible_facts.some_fact') | list }}"
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2017-08-02 19:57:58 +00:00
|
|
|
# Example setting facts so that they will be persisted in the fact cache
|
|
|
|
- set_fact:
|
|
|
|
one_fact: something
|
|
|
|
other_fact: "{{ local_var * 2 }}"
|
|
|
|
cacheable: true
|
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
# As of 1.8, Ansible will convert boolean strings ('true', 'false', 'yes', 'no')
|
|
|
|
# to proper boolean values when using the key=value syntax, however it is still
|
|
|
|
# recommended that booleans be set using the complex argument style:
|
|
|
|
- set_fact:
|
|
|
|
one_fact: true
|
|
|
|
other_fact: false
|
|
|
|
|
|
|
|
'''
|