Commit Graph

53 Commits

Author SHA1 Message Date
Gaudenz Steinlin cccf4c03f1
Ensure consistent ordering of network_mappings
The provider_networks module returned the network_mappings in a random
order changing with every invocation. This returns the entries sorted
and adds a test to ensure the ordering is consistent between
invocations.

Change-Id: Iaec4534ebd8ff80cf7c7e3a1c8f187dd3990e4bc
2023-12-21 14:12:15 +01:00
Dmitriy Rabotyagov aa277377ac Generate SSH certificates for delegation test
Last test, that tries to delegate to a host that is not part of inventory
requires an SSH access to such host.
Since with latest changes to lxc_hosts repo [1] we do not install
SSH server nor provision SSH keys to containers by default.

As additional profit we now have a functional test of the ssh_keypairs
role.

[1] https://review.opendev.org/c/openstack/openstack-ansible-lxc_hosts/+/889945

Change-Id: Ia6b0f4406d0c2244327c2eb9fdee9a53462557c5
2023-10-19 18:47:48 +00:00
Dmitriy Rabotyagov 2b42bf0359 Use hostnamectl command to fetch hostname
In CentOS Stream 9 we don't have /etc/hostname file. At the same time
hostnamectl provides expected output. Thus we switch to more modern
way of fetching hostname that works equally good for all distros.

Change-Id: If5212d5432cc49fb9745f77ebbef9525e2a3b393
2022-12-28 21:35:01 +00:00
Dmitriy Rabotyagov db77cec609 Add pki role to local a-r-r
Change-Id: I6de017f6fe41ab2fc43ef5db77a6b8a6e87c741a
2021-07-02 12:32:50 +03:00
Jonathan Rosser 837b5cee08 Use ansible_facts[] instead of fact variables
See https://github.com/ansible/ansible/issues/73654

Change-Id: I03791a244615238d8c35dea14a81dd6e28e7374d
2021-03-16 08:27:40 +00:00
Jonathan Rosser d077aded47 Remove references to unsupported operating systems
All references to Gentoo, SUSE, Debian stretch and Centos-7  are removed.
Conditional tasks, ternary operators and variables are simplified where possible
OS specific variables files are generalised where possible

Change-Id: I4f0db0ab31e9d394d7f741aff88b53bc9129daa1
2021-03-16 08:27:05 +00:00
Jimmy McCrory 0b2981a5b5 Use privilege escalation to attach to containers
When the play context contains 'become' for ansible privilege
escalation, apply the configured become method (sudo) to the command
used to attach to a container. This allows for non-root users to use the
connection plugin to connect to containers.

Closes-Bug: 1645732

Change-Id: I485bd0aa850f39201654c808f0c61d26113f6390
2020-12-05 00:20:19 +00:00
Jonathan Rosser 871d91cf26 Optimise linear strategy access to physical host variables
Change from using variable manager to the var we already have for
the physical host. This saves nearly 50% time for re-running
playbooks/lxc-container-create.yml

Change-Id: Ic50763f9c74746ef94925a4dd52d16e1f313711b
2020-06-24 20:13:53 +03:00
Jonathan Rosser e81fa854bd Ansible 'changed' is a test not a filter
This syntax is no longer valid for ansible 2.9 so must be changed

Change-Id: Ib3c15a28bebbb98a38b3715187e92a742bc2117e
2020-05-14 07:02:04 +01:00
Duncan Walker 24fe4789c8 Removing unused filters from osa plugins
pip_constraint_update, filtered_list,
git_link_parse, git_link_parse_name filters
have no reference inside OSA
hence removing these filters.

Change-Id: Id4bc4ab87ac4b60121290ad6cbbd143962357d39
Closes-Bug: #1826245
2019-09-20 09:47:30 +01:00
Zuul fa93ca1b24 Merge "Removing unused filters from osa plugins" 2019-07-30 19:08:40 +00:00
mattycarroll fc9e016e90 Remove bit_length_power_of_2
This change is to remove bit_length_power_of_2 from this repo since
it has been moved to openstack-ansible-openstack_hosts. This is
because it is only used by that repo.

Depends-On: I543328db49dc6b7bbb05878503dbb3d337a18558
Change-Id: I9e2b3e10ec42d246d203e363f0c737b8824ccd47
Closes-bug: #1826242
2019-07-27 21:37:47 +00:00
namrata aba5c08446 Removing unused filters from osa plugins
pip_requirement_names filter has no reference inside OSA
hence removing the same.

Change-Id: I3f7038f3add6a05c2b2fb038818aa92d370e2e81
Partial-Bug: 1826245
2019-07-26 17:29:04 +05:30
Zuul 6c80d69bdd Merge "Removal of netloc filters" 2019-04-24 18:58:48 +00:00
Jesse Pretorius 00c22491d0 Remove py_pkgs and packages_file lookups
Neither of these lookups are used in OSA any more, so we can
remove them.

Change-Id: Ib1c19eaf5a16d59e91d5c6c5ced9b30781b1f69b
2019-04-24 14:50:00 +01:00
Georgina 6482c25017 Removal of netloc filters
The ansible urlsplit filter added in 2.4 means that maintaining the
filters netloc, netloc_no_port and netorigin should no longer be
necessary.
All usages of these filters within other openstack repos have been
updated to use urlsplit and merged.

Change-Id: Ief1ec06e205bae7ec114fe0b9bd7d9c4973383dd
Closes-Bug: #1820830
2019-04-23 13:37:52 +00:00
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
Jimmy McCrory 83c5785ba8 Allow basic auth in netloc_no_port filtered URLs
Update the netloc_no_port filter to parse a URL using the 'hostname'
attribute instead of splitting the netloc before the first colon, where
a username might be provided.

Change-Id: I9a0d01eac1e44de121fc7c6753cfa1bc2ed4318d
2018-10-29 00:10:01 -07:00
Jimmy McCrory 3eb9d79a1a Fix connection plugin for Ansible 2.6
inventory_hostname is not reliable to be used as container_name. When
delegating in 2.6+, the inventory_hostname of the delegating host is
passed to the connection plugin, additionally when a host doesn't have
its own container_name variable a cached inventory_hostname is used in
its place.

To get the connection plugin working with Ansible 2.6 this change
essentially allows the container_check to fall through when delegating
to physical hosts or hosts not in the inventory by:
- removing inventory_hostname as a fallback for container_name
- unsetting container_name when delegating to a known physical host
- unsetting container_name when delegating to a host not mentioned in
  the inventory

container_name can no longer be used as a group variable based on
inventory_hostname, it will need to be an inventory/host variable for
each individual host.

Also, when container_user is used the remote_tmp path needs to be set to
a system writable directory instead of the root user's home.

Change-Id: If2eb4c16273e19599f6ec3f0cba6b3573912c6a0
2018-10-18 13:27:27 -07:00
ZhijunWei cfb687a64a use include_tasks instead of include
include is marked as deprecated since ansible 2.4[0]
[0] https://docs.ansible.com/ansible/2.4/include_module.html#deprecated

Change-Id: Ide1e68552bde4d9e9e85c13cf45d2b40a855432e
2018-08-19 12:25:15 -04:00
Zuul f655fcbaab Merge "Revert "Add a get_nested filter"" 2018-07-20 17:36:00 +00:00
Jesse Pretorius (odyssey4me) 1e436a2f43 Revert "Add a get_nested filter"
This reverts commit 80a1262252
because we're not using it, and using json_query is simple enough.

Change-Id: I8d5fba867eceb6892a7a995a9b86153e88353480
2018-07-20 11:22:38 +01:00
Zuul ad66545fe5 Merge "Fix physical_host loading from group/host vars" 2018-07-14 00:38:28 +00:00
Logan V 3f224cdef7 Fix physical_host loading from group/host vars
Commit I76af71ffe19b2a8afb18ed731f1362a4e399c613 broke the ability
to define physical_host in host_vars and group_vars. The physical_host
is only loaded from the ini inventory.

Change-Id: I3798529cf2bf73afbff2d2ef0f3fe17d91123fbc
2018-07-12 18:13:18 -05:00
Jean-Philippe Evrard a3add1e7b0 Fix usage of "|" for tests
With the more recent versions of ansible, we should now use
"is" instead of the "|" sign for the tests.

This should fix it.

Change-Id: I015f0687a24ab9727a6a43fa0c3da709ce72530d
2018-07-12 16:56:15 +02:00
Logan V 76bec48bc9 Update physical host mapping for ansible 2.4+
On ansible 2.4+, when 'ansible_host' is defined in the inventory
ini file, the physical host mapping in the strategy plugin works as
expected. However, if the ansible_host setting is in host_vars/<host>.yml,
then the mapping does not work.

Change-Id: I22c09c4de86233329f337b535b709cd5320c40d3
2018-06-26 06:30:59 +00:00
fpxie 6a70955616 Trivial: Fix the pep8 warning
The yaml should start with "---"

Change-Id: Ie60366cccd6e3c3e0ab8cdeb96a39e31b0565c85
2018-05-08 17:30:51 +08:00
Zuul c8231e07ca Merge "Fix delegation to hosts not in inventory" 2018-04-22 16:32:07 +00:00
Jonathan Rosser 477b0a7d20 Add test for conditional delegation
This pattern is used in several openstack-ansible roles to control
if tasks are run on the deploy or target hosts, as chosen by the
deployer

Change-Id: I598353c8915762906459146daf4f5a2bbe74fba3
2018-04-12 09:48:53 +00:00
Jimmy McCrory 587eea909c Fix delegation to hosts not in inventory
When using Ansible 2.5, delegation of a task from a container to a host
that is not mentioned in the inventory is currently broken.

The connection plugin works by comparing the host vars 'container_name'
and 'physical_host' to determine if a target host is a container. Both
of these variables are specific to hosts within an OSA generated
inventory. When delegating to a host outside of the inventory however,
the variables will remain cached from the originating host, so a task
wouldn't actually delegate at all.

This is fixed by checking that the 'inventory_hostname' is the same as
the 'container_name'.

Change-Id: I69f2eed35859bdc149e5ed21441eab7c8a8352cf
2018-03-29 20:29:02 -07:00
Jesse Pretorius f54c191b61 Remove tests-repo-clone.sh
Now that run_tests.sh handles the tests repo clone, we can
remove the use of the older tests-repo-clone.sh script.

Change-Id: Id638de82323d45016b5f5c4b7f5c9711ec89c88f
2018-03-28 10:17:20 +01:00
Logan V c03c7db223 Add tests for MultiStringOp
Change-Id: Id9fe6c119b0e99a956c7c42581699842f99e02aa
2018-03-24 01:39:16 +00:00
Logan V 37f1df3a33
Add tests for container_user connection attribute
Add a test to ensure container_user executes as the correct user
inside the container.

Change-Id: I0f8443ee4681af38fc09135668b12f852f2dcb31
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
2018-03-21 11:24:03 -04: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
OpenStack Proposal Bot 802ac8ffab Updated from OpenStack Ansible Tests
Change-Id: Icfe14a922a38132ec2a2fe83d31eea142c2ef7db
2018-02-14 20:08:00 +00:00
Zuul 0bc785dd50 Merge "Preserve comments in INI files" 2017-11-29 12:33:55 +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
Jesse Pretorius f37321af6b Resolve ansible-lint test failures
With the merge of https://review.openstack.org/520177 in the
tests repo some ansible-lint failures which previously were
not being picked up are now detected.

This adds the appropriate skip tags to the tasks so that they
are not evaluated by ansible-lint.

Change-Id: I820aa77ac097d4f3d043fb434255923847e3d650
2017-11-20 12:07:34 +00:00
Jean-Philippe Evrard ead9047761 Initial OSA zuul v3 role jobs
This patch implements an initial set of jobs intended to match
the current job execution method. It does not intend to improve
how the jobs are executed - only to replicate what is currently
in openstack-infra/openstack-zuul-jobs and provide the platform
to iterate on.

Change-Id: Id5a41c4f09bfc63b373e83493dd85a53850bd71c
2017-10-17 20:43:54 +00:00
OpenStack Proposal Bot e0002ca1bb Updated from OpenStack Ansible Tests
Change-Id: I99d21e2168832da4ac57fd503cd0d20f87e971be
2017-10-12 20:45:18 +00:00
Logan V b819a87394 Add container-aware connection plugin tests
- Test the container awareness of the connection plugin (the lxc-attach
  execution functionality when container_name is set on a host).

- Test delegation to containers

Depends-On: Idb186a061a396713a0e449d47ec262b30d5006ca
Change-Id: I2331d5d5c9cf3d4f8fc83639f6047092232f5887
2017-09-14 04:56:57 +00: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
Nolan Brubaker 80a1262252 Add a get_nested filter
When accessing nested facts, such as in ansible_local sections, guard
statements in the when clause can get quite long, due to having to
repeate the 'in/not in' logic for every key at every level.

The get_nested filter attempts to instead to move the guard into a
single line, making the conditions easier to write and maintain.

As example,

   ('openstack_ansible' not in ansible_local or
    'swift' not in ansible_local['openstack_ansible'] or
    'venv_tag' not in ansible_local['openstack_ansible']['swift'] or
    ansible_local['openstack_ansible']['swift']['venv_tag'] == swift_venv_tag)

 could be rewritten as

     get_nested(ansible_local, 'openstack_ansible.swift.venv_tag') == swift_venv_tag

Change-Id: I3b43c25c8783c43cf5285f2b3e7267b2c5712ea0
2017-07-07 19:42:39 +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
Jesse Pretorius a900eca8be Use zuul-cloner for tests repo in OpenStack-CI
When executing the tests repo clone in OpenStack-CI,
use zuul-cloner instead of git to enable cross-repo
testing. This ensures that if a dependent patch from
the tests repo is noted using 'Depends-On: <change-id>'
in the commit message, that patch will be included.

Depends-On: Idce7abebf32f24c356a27e099fbca954d917402b
Depends-On: I5da7802d61d2ab6b03908138e3a3ed2db22e3d29
Change-Id: Ib9e5f4c93529b6bf74e37ce9f2feb0faa87a3b81
2017-05-10 18:49:54 +01:00
Jean-Philippe Evrard 8bfffe39cf Add Packages file parsing lookup
This is a lookup in case you need to parse a ubuntu repo Packages file
for a list of packages. It's useful in osa if you want to have a mirror
of an ubuntu repo, and output a list of its packages, with their
location and checksum.

You can use the output dict to feed another tool (for example
downloading with aria).

Change-Id: I10ba72f0b64267ae6afe57317e135d782445e934
2017-03-27 11:43:23 +00:00
Logan V 5d6c040d18 Implement tag filter strategy
Renames the "artifacting" strategy to "tagfilter" and implements
a more generic tag skipping implementation that can be defined
from within the ansible vars structure dynamically on a per-host,
per-group, or per-playbook basis.

To use the tagfilter strategy, run the playbook with
strategy: tagfilter

and define a hostvar named "skip_tags". Skip tags can be a string
or a list, and any tag CONTAINING a skip tag (an exact match is not
needed) will be skipped.

Also added is a check for a var called "skip_handlers", defaulted
to True. When skip_handlers is enabled, no handlers will be run
regardless of whether the task is skipped or not. If set to False,
handlers will be allowed to run as normal except when tasks are
skipped by the skip_tags.

Change-Id: I649707e6744e03763c4e786d203716ebf657ab48
2017-02-24 09:35:48 -06: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 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