Commit Graph

25 Commits

Author SHA1 Message Date
Jesse Pretorius b28590f5bd Remove the config_template module
The config_template action module has now been moved into its own git
repository (openstack/ansible-config_template). This has been done to
simplify the ability to use the plugin in other non OpenStack-Ansible
projects.

As part of this, we now need to remove the environment settings given
to ansible so that the common tests repo settings in ansible.cfg take
effect.

Related-Bug: 1791258
Depends-On: https://review.openstack.org/635841
Change-Id: I3a7d8c0c248febc4223029e076062ca68312b104
2019-02-11 16:43:57 +00:00
Andy McCrae 5c70fb05d8 Fix config_template to work with Ansible 2.6
In Ansible 2.6 the copy module now recognizes the "_original_basename"
option and not the "original_basename" option. In order for this module
to work with versions less than 2.6.0 and 2.6.0+ we need to allow an if
statement based on the version of Ansible being used.

Change-Id: I3f7a12dec77ea6e8e3c9fcae6ce9c162df57e50c
(cherry picked from commit fcf669b78c9266212a07a0a1caef6ff73a7cef73)
2018-08-02 09:41:23 -06:00
Kevin Carter 662a2805c0 Retain the ordering when using with MultiStringOp
When using config_template with a MultiStringOp the order was subject to
change because of the use of set theory. This change converts the use of
sets to tuples which allow us to retain the ability to override options
without losing the ordering of keys.

Change-Id: Id0bba86629a33ce74528c0bd51b11183f5315d86
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2018-03-22 14:35:08 +00:00
Andy McCrae a5ef4eadd1 Utilise sorted to ensure no random changes
As part of the ceph-ansible project, this change was put in:
ec042219e6
This was to handle the case where the config would change, initiating a
restart handler, even though no actual change happened.

We can juse use sorted() since we are passing back a list with .items()
which can then be sorted.

The above change didn't include a change to ensure the order of the
sections, which meant that although the individual items were sorted the
sections could change order causing unnecessary changes.

Additionally, this adds a test to retemplate the file 3 times, with a
lot more sections to ensure the order remains the same, this will fail
when the config template changes even though no changes have happened.

Change-Id: I7c7cd9ef1dd767a2a5d754ac4663cf8655dd60c2
2018-03-16 16:33:29 +00:00
Flavio Percoco 3f5a274374 Preserve comments in INI files
config_template currently strips comments out from the INI files. This
commit adds support for comments.

The default ConfigParser supports reading comments but it doesn't writes
them back. There are other libraries that have better support for
comments, however, adopting another library would require a bigger
refactor of this code.

Change-Id: I376be69cd2cf34dc147f9ade716791125a424e2c
2017-11-23 14:46:18 +01:00
Jimmy McCrory 7593eb3ba9 Remove plugin compatibility with Ansible v1.9
Ansible v1.9 was last used by OSA in Mitaka. The extra code to keep the
config_template and py_pkgs plugins compatible should no longer be
needed.

Change-Id: I14b32af1dc9bfe8b09c52f0205afaaad9139b58c
2017-09-12 10:41:49 -06:00
Jimmy McCrory ca0cf34163 Python3 compatibility for config_template overrides
Strings are used where they were encoded to bytes and cast back to
strings before. The StringIO module is imported to retain backwards
compatibility with Python 2.7. Also, the convert_2_string function is
removed and its usage replaced with Ansible's to_text function.

Change-Id: I396d96b8047e653f4526350375abc1f5f0dcd756
Fixes-Bug: 1711347
2017-09-06 15:05:49 -07:00
Kevin Carter 2d1dd94264
remove the use of iteritems
iteritems is a py2 callable and will break when using py3.

Change-Id: Icea444baea8f3597cb8dd24e3d61e9ed0926cdf5
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2017-08-02 15:04:48 -05:00
Jenkins c5d588fce9 Merge "Fix dumping hostvars to yaml from overrides" 2017-08-02 14:01:53 +00:00
Logan V 2a286fb0fb config_template python 3 compatibility
d.iteritems() -> d.items()

Refs:
http://legacy.python.org/dev/peps/pep-0469/
https://stackoverflow.com/questions/10458437/what-is-the-difference-between-dict-items-and-dict-iteritems
https://stackoverflow.com/questions/24189379/what-is-the-advantage-of-iteritems

Change-Id: Ie5a46ddea8927e4c6d585789fcc8a552943106be
2017-08-01 15:12:05 -05:00
Logan V 6d496d6c5b Fix dumping hostvars to yaml from overrides
Using AnsibleDumper adds support for dumping the internal ansible
data types that are used in hostvars.

Fixes-Bug: #1707265
Change-Id: Ie59bbef31306cd3e99aa827db875922e17084e83
2017-08-01 19:36:36 +00:00
Miguel Alex Cantu 76d5f02a32 Add ignore_none_type to config template
It is sometimes useful to tell ConfigTemplateParser to write
out options that are valueless and not suffixed with '=' or ':',
such as when overriding a my.cnf.

This commit adds the 'ignore_none_type' attribute to the config_template
module. If this attribute is set to false, then valueless options will be
written out to the resultant INI file as-is, without the '=' or ':' suffix.

Change-Id: I5c88b2019c01b44193a5d0df9299ecce6de52f01
Partial-Bug: #1693234
2017-06-26 19:12:43 +00:00
Miguel Alex Cantu 371cbc1fde Handle 'dict' type as input of 'content'
When users specificy the 'content' attribute when
using the config_template module, it's possible that
this input can be a dict. This commit handles
dictionary input, and dumps it accordingly based
on 'config_type'

Change-Id: I1f12810ad7ce5746f8938ec9d608c532ba530d58
2017-06-22 21:46:31 +00:00
Kevin Carter 80d59cdf96
Added yaml class dumper to support indentation
The default py yaml `safe_dumps` keeps to the yaml spec which states
incremental indentations are not required. Sadly, without the
indentations some consumers of yaml configurations files will break.
This commit adds an incremental indentation dumper to cater for all
yaml configuration consumers.

Change-Id: Ifa5bcc6ff9f0a9cb5e619e62d0356f5d6887ca6e
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2017-01-25 23:50:31 -06:00
Jean-Philippe Evrard 6d76bfe7df Cleanup temporary files after content argument usage
When using content: the config_template module will create a
temporary file. This patch ensures a deterministic path to the
temp file is used, and removes it at the end of the module
execution.

Change-Id: I3b3354178ba1a2b9c95decb3d3e0c9a1c2689056
2017-01-03 10:12:14 +00:00
Jean-Philippe Evrard 1f404d7f97 Introduce content argument
Copy module can take content argument, I think we should introduce this
feature to config_template. It brings the possibility to use lookups for
inline passing of content to template.

Example, we could use:

config_template:
  content: "{{ lookup('file',<file>) }}" to replace current behavior

or:

config_template:
  content: "{{ lookup('url','<url>',wantlist=True) | join ('\n') }}"

to bring inline templating of external sources.

Change-Id: Id5b2743d309f0313603afbbf84279ce0b1e49cfb
Signed-off-by: Jean-Philippe Evrard <jean-philippe.evrard@rackspace.co.uk>
2016-12-15 12:08:17 +00:00
Jean-Philippe Evrard 5bf7a5c3f1 Adapt to_unicode and to_bytes for ansible 2.2
The config_template is using the old ansible objects, this should
make it work with the newest standards.

Change-Id: I9159be497c201ca6c2f558336843be5175f0ee2c
Closes-Bug: 1640458
2016-11-09 12:00:23 +00:00
Kevin Carter 5f42556157 Updated for deprecated "ansible_ssh_user"
Ansible has changed the variable ansible_ssh_user to ansible_user
this change adds support for the option ansible_user while 
maintaining compatibility with the legacy option.

Change-Id: I032a3562ccebbbf8f7248bfbec1e2c59b452587b
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2016-10-25 21:22:21 +00:00
Jimmy McCrory 2f6cac2cf6 Remove deprecated first_available_file
The first_available_file option on tasks has been deprecated in
Ansible 2, and will be removed in 2.2. Remove its use in the
config_template plugin similarly to its removal from the upstream
template plugin [0].

[0] https://github.com/ansible/ansible/pull/17643

Change-Id: Icd4f70706979a3f59dd93f116d1c5ef96d66edbe
2016-10-19 11:15:44 -07:00
Kevin Carter 80beba88da Add option to toggle list extensions
By default a list item in a JSON or YAML format will extend if a its already
defined in the target template and a config_override using a list is being set
for the existing "key".

This change allows that functionality to be toggled on or off. The boolean
option to enable list extension is ``list_extend``.

To maintain the API this feature will remain True by default.

Co-Authored-By: Travis Truman <travis_truman@cable.comcast.com>
Change-Id: I97e06aef2cc778f048f3d6863fe61d10eddb8602
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2016-09-09 16:15:00 -05:00
Kevin Carter f946160dd0
Added option to support case-insensitive keys
This change allows keys in INI format to be any case.
The default ConfigParse module sets this to be lower
however in some cases keys are needed to be upper and/or
mixed.

Change-Id: I4e0dedb1b73ee596929bd425af6b0aaefd3a6c27
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2016-04-21 16:09:18 -05:00
Kevin Carter cd47eda77b Update the config_template plugin
These changes address 2 issues:

* The config template plugin in v1 mode was not respecting a list
  of integers and would cause a stacktrace because the ConfigParse
  module expects everything written to be a string.
* The config template plugin in v2 mode was not properly handling
  the multi-string-op type due to an oversight in the ``_option_write``
  method.

With these updates the config template is now able to better support
all of the potential options that could be thrown at it when writing
an INI config file.

These issues we're discovered while working with the ceph-ansible
project and a mirroring PR has been created here:
https://github.com/ceph/ceph-ansible/pull/707

Change-Id: I051096abae883ac81195d4538140566b69f8996c
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2016-04-12 08:55:36 +00:00
Kevin Carter f9e6f567ba
Update the config_template plugin for ansible2
This change updates the config_template plugin to load
the version of the config_template needed based on the
detected version of ansible running. Note, Once the
upstream change merges for ansible 2 [0] we should
drop the ansible 2  version of this plugin.

[0] - https://github.com/ansible/ansible/pull/12555

Change-Id: Ifbdde0f30ee2bd8025ede07c86234527ba9891db
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2016-03-30 16:13:26 -05:00
Kevin Carter b42faff784
Add MultiStrOps support to config_template
This change adds the MultiStrOps variaable type to the config
template parsing as well as supports multi string options when
passing configuration overrides.

This is made prossible by using the set type for options found within
config overrides and creating a custom dictionary class that allows
for multiple keys to be stored as a set. When the config_template
encounters a set type it will process and reder value as a
MultiStrOps.

Set types are defined in yaml via the "?" entry.

Example Overrides:
  things:
    - 1
    - 2
  multistrops_things:
    ? a
    ? b

Example Rendered Config:
  things = 1,2
  multistrops_things = a
  multistrops_things = b

Change-Id: I2193ea2eb7f839c3151c2c96f9dfe86f141e5a15
Closes-Bug: #1542513
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2016-02-10 09:12:36 -06:00
Jesse Pretorius fc411eaf89 Rename plugins folders to standard Ansible names
The standard Ansible names for the plugins folders [1] are singular.

This patch renames our plural names to singular names so that when
the plugins are downloaded into a default location there is no further
configuration required.

[1] https://github.com/ansible/ansible/blob/devel/lib/ansible/constants.py

Change-Id: Ib965750f267d11287a6196e2544c3a014a3e2029
2016-02-10 00:54:11 +00:00