Commit graph

14 commits

Author SHA1 Message Date
Till Maas
db6384f83c Print network provider early
The list of packages to install depends on the network provider, so
print it out early.
2018-08-24 15:21:03 +02:00
Till Maas
4b9c91763b Use nm provider by default only when NetworkManager is running
- Use initscripts as provider except when NetworkManager is running
- Rename network_provider_default to network_provider_os_default, since
it contains the default based on the OS
2018-08-01 18:32:01 +02:00
Till Maas
5f30c5b5e3 Use set_facts to set default provider
This avoids symlinks that do not work on Windows:
https://github.com/linux-system-roles/network/pull/64#issuecomment-401740870
2018-07-09 11:56:01 +02:00
Till Maas
3e8cb619b8 Work around slow package manager 2018-07-06 21:16:33 +02:00
Till Maas
f0d0e0637b Add SPDX-License-Identifier headers 2018-03-13 10:06:30 +01:00
Thomas Haller
16ad34c20a role: improve making "network_provider" configurable via host vars
The role currently supports two providers: "nm" and "initscripts".

The provider is autodetected by loading one of the vars/*.yml files
(where the default is set via the internal "network_provider_default" variable).
The user can still overwrite the provider, by explicitly setting the
"network_provider" variable.

Depending on the provider there is the list of packages that shall be
installed and the service to start. Selecting this was broken before.

This is now fixed and works like following:

The variables "network_service_name" and "network_packages" can be
specified by the user as host variables. But usually the user wouldn't
want to do that. Instead, those settings depend on "network_provider".
The role looks into the internal "_network_provider_setup" dictionary,
which defaults to "network_service_name_nm", "network_service_name_initscripts",
"network_packages_nm", and "network_packages_initscripts".

These default variables are initialized in "defaults/main.yml" as well,
but they could be overwritten via "vars/*.yml" files, or via any other
mechanism.

https://github.com/linux-system-roles/network/pull/14
https://bugzilla.redhat.com/show_bug.cgi?id=1485074
2017-09-25 11:37:48 +02:00
Thomas Haller
5deb2afd46 library: don't do anything for "up" and "down" states if already in state
The states "up" and "down" previously would always change state. That
is, specifying them in the playbook will always invoke `ifup` (or
`ifdown`) or the corresponding of `nmcli connection up` (or `nmcli
connection down`).
That was intentional behavior, because the role doesn't really know which
profile is currently active. That is certainly the case for "initscripts",
where the role has almost no information about the current runtime
state. For "nm" provider, the role knows whether the connection is
already active. However, that alone also does not guarantee that the
current runtime state is idential to what would be the result of an
explicit `nmcli connection up`.
Hence, to be sure that the current state is always as expected, the role
would always explicitly issue the commands and report "changed=1".

That is quite harmful, because running the same role multiple times
should not report changes every time. Also, issuing `ifup` may behave
badly, if the interface is already configured.

Now, try to determine whether the desire "up" or "down" state is already
reached and do nothing.

For "nm" provider that is easy and quite safe. There is still the
possibility to trick the role into thinking that the right configuration
is active, when it actually is not. For example via `nmcli device
modify` on the host. But in general, it should work just fine.
Especially, if the admin manually modifies the runtime state, it may be
just desired for "state: up" not to change anything.

For "initscripts" this is much more fragile. There isn't really much
that can be done about it, because the role doesn't know what is currently
configured on the system.

There is also a new option "force_state_change" to restore the previous
behavior.

https://bugzilla.redhat.com/show_bug.cgi?id=1476053
2017-08-28 12:10:13 +02:00
Thomas Haller
29c7008f61 network: use top-level variables instead of nested "network" variable
The role already supported a default variable ("network_provider") and
host variables ("network_provider_default", "network_service_name",
"network_packages").

Don't use nested variables under "network" like

  network:
    provider:
    ignore_error:
    connections:

instead promote them all to top-level variables like:

  network_provider:
  network_ignore_error:
  network_connections:

This seems more consistent (as we already have multiple top-level
variables), it seems to follow ansible style, and it makes it easier
to overload individual variables via conditional include files.
2017-05-09 13:58:31 +02:00
Thomas Haller
52318732bb tasks: name "vars" file by the matching "{{ ansible_distribution }}"
This fixes the role to run on Fedora and CentOS.
2017-05-02 13:28:01 +02:00
Thomas Haller
8682cb64b8 module: support a 'ignore_errors' argument
It's more idiomatic for ansible then "on_error".

'ignore_errors' can be specified as a module argument.
But it can also be specified on a per-profile level,
with the intuitive behavior that the per-profile setting
overwrites the per-module setting.
2017-02-19 21:57:55 +01:00
Thomas Haller
edcb4a2850 library: let the module handle all connections at once
Instead, of having the tasks call the "network_connections.py"
library for each connection profile individually (using with_items),
pass all profiles at once.

The advantage is:

 - the module can validate the input arguments better as it has
   access to all profiles. For example, when a slave connection
   refers to another master profile from the same play. Previously,
   each invocation of the module only sees the current profile and
   cannot verify whether the reference is valid.

 - while configuring the network, the play might need to shortly
   disconnect the control connection. In the previous way, after
   tearing down the network the target host becomes unreachable for
   ansible and the following steps cannot be executed anymore.
   Now, all steps are done as a whole on the target host, via
   one connection. If the host becomes unreachable for a short
   time, that is not a problem as long as the connectivty is
   restored at the end.
   Ansible also supports to switch the host IP (or SSH port). With
   this new way, the ansible play can apply a bunch of profiles
   autonomously and the ansible play can potentially handle a changing
   IP configuration.
2017-01-12 19:22:52 +01:00
Sam Doran
9c54c68858 Restructure role
Change default variables to include lookup table.
Change tasks to set variables based on distribution version.
2016-12-05 16:07:19 -05:00
Sam Doran
1d17b3fa93 Use multi-line YAML syntax 2016-12-05 13:18:05 -05:00
Thomas Haller
ac35802240 first version 2016-12-05 18:14:20 +01:00