Move TripleO ansible inventory file to .ansible/inventory folder
Change-Id: I2ac2615e7c18e9feb1214d19d0f862bbf32999ee
This commit is contained in:
parent
6791976345
commit
b3fbd45f5a
4
.gitignore
vendored
4
.gitignore
vendored
@ -45,8 +45,8 @@ tobiko.conf
|
||||
.infrared
|
||||
workspace.tgz
|
||||
|
||||
# Tripleo files
|
||||
tripleo-hosts.yaml
|
||||
# Ansible files
|
||||
.ansible/
|
||||
|
||||
# Report files
|
||||
tobiko_results*
|
||||
|
@ -98,7 +98,7 @@ class AnsiblePlaybook(tobiko.SharedFixture):
|
||||
-> typing.List[str]:
|
||||
filenames = list(inventory_filenames)
|
||||
filenames.extend(self._inventory_filenames)
|
||||
filenames.extend(tobiko.tobiko_config().ansible.inventory)
|
||||
filenames.extend(tobiko.tobiko_config().ansible.inventory_files)
|
||||
existing_filenames = []
|
||||
for filename in sorted(filenames):
|
||||
filename = tobiko.tobiko_config_path(filename)
|
||||
|
@ -21,7 +21,7 @@ from oslo_config import cfg
|
||||
|
||||
GROUP_NAME = 'ansible'
|
||||
OPTIONS = [
|
||||
cfg.ListOpt('inventory',
|
||||
cfg.ListOpt('inventory_files',
|
||||
default=['/etc/ansible/hosts'],
|
||||
help="Default Ansible inventory files"),
|
||||
]
|
||||
|
@ -23,10 +23,9 @@ from tobiko import tripleo
|
||||
PLAYBOOK_DIRNAME = os.path.join(os.path.dirname(__file__), 'playbooks')
|
||||
|
||||
|
||||
@tripleo.skip_if_missing_undercloud
|
||||
@tripleo.skip_if_missing_tripleo_ansible_inventory
|
||||
class OpenShiftTest(testtools.TestCase):
|
||||
|
||||
@tripleo.skip_if_missing_tripleo_ansible_inventory
|
||||
def test_ping_all_hosts(self):
|
||||
tripleo.run_playbook_from_undercloud(
|
||||
playbook='ping-shiftstack.yaml',
|
||||
|
@ -13,20 +13,20 @@
|
||||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
from tobiko.tripleo import _ansible as ansible
|
||||
from tobiko.tripleo import _ansible
|
||||
from tobiko.tripleo import _overcloud as overcloud
|
||||
from tobiko.tripleo import _topology as topology
|
||||
from tobiko.tripleo import _undercloud as undercloud
|
||||
|
||||
|
||||
get_tripleo_ansible_inventory = ansible.get_tripleo_ansible_inventory
|
||||
get_tripleo_ansible_inventory = _ansible.get_tripleo_ansible_inventory
|
||||
get_tripleo_ansible_inventory_file = \
|
||||
ansible.get_tripleo_ansible_inventory_file
|
||||
has_tripleo_ansible_inventory = ansible.has_tripleo_ansible_inventory
|
||||
read_tripleo_ansible_inventory = ansible.read_tripleo_ansible_inventory
|
||||
_ansible.get_tripleo_ansible_inventory_file
|
||||
has_tripleo_ansible_inventory = _ansible.has_tripleo_ansible_inventory
|
||||
read_tripleo_ansible_inventory = _ansible.read_tripleo_ansible_inventory
|
||||
skip_if_missing_tripleo_ansible_inventory = \
|
||||
ansible.skip_if_missing_tripleo_ansible_inventory
|
||||
run_playbook_from_undercloud = ansible.run_playbook_from_undercloud
|
||||
_ansible.skip_if_missing_tripleo_ansible_inventory
|
||||
run_playbook_from_undercloud = _ansible.run_playbook_from_undercloud
|
||||
|
||||
find_overcloud_node = overcloud.find_overcloud_node
|
||||
list_overcloud_nodes = overcloud.list_overcloud_nodes
|
||||
|
@ -31,9 +31,9 @@ def get_tripleo_ansible_inventory():
|
||||
return tobiko.load_yaml(fd)
|
||||
|
||||
|
||||
def has_tripleo_ansible_inventory():
|
||||
def has_tripleo_ansible_inventory() -> bool:
|
||||
inventory_file = get_tripleo_ansible_inventory_file()
|
||||
return inventory_file and os.path.isfile(inventory_file)
|
||||
return bool(inventory_file)
|
||||
|
||||
|
||||
skip_if_missing_tripleo_ansible_inventory = \
|
||||
@ -41,22 +41,12 @@ skip_if_missing_tripleo_ansible_inventory = \
|
||||
has_tripleo_ansible_inventory)
|
||||
|
||||
|
||||
def get_tripleo_ansible_inventory_file():
|
||||
return tobiko.setup_fixture(TripleoAnsibleInventoryFixture).inventory_file
|
||||
|
||||
|
||||
class TripleoAnsibleInventoryFixture(tobiko.SharedFixture):
|
||||
|
||||
inventory_file = None
|
||||
|
||||
def setup_fixture(self):
|
||||
tripleo = _config.get_tripleo_config()
|
||||
self.inventory_file = inventory_file = tobiko.tobiko_config_path(
|
||||
tripleo.inventory_file)
|
||||
if inventory_file is not None and not os.path.isfile(inventory_file):
|
||||
content = read_tripleo_ansible_inventory()
|
||||
with io.open(inventory_file, 'w') as fd:
|
||||
fd.write(content)
|
||||
def get_tripleo_ansible_inventory_file() -> typing.Optional[str]:
|
||||
if _undercloud.has_undercloud():
|
||||
inventory_file = _config.get_tripleo_config().inventory_file
|
||||
if inventory_file:
|
||||
return tobiko.tobiko_config_path(inventory_file)
|
||||
return None
|
||||
|
||||
|
||||
READ_TRIPLEO_ANSIBLE_INVENTORY_SCRIPT = """
|
||||
@ -86,19 +76,27 @@ def read_tripleo_ansible_inventory():
|
||||
return sh.execute('/bin/bash', stdin=script, ssh_client=ssh_client).stdout
|
||||
|
||||
|
||||
def create_tripleo_inventary_file(inventory_file: str):
|
||||
content = read_tripleo_ansible_inventory()
|
||||
tobiko.makedirs(os.path.dirname(inventory_file))
|
||||
with io.open(inventory_file, 'w') as fd:
|
||||
fd.write(content)
|
||||
|
||||
|
||||
class UndercloudAnsiblePlaybook(ansible.AnsiblePlaybook):
|
||||
|
||||
@property
|
||||
def ssh_client(self) -> ssh.SSHClientType:
|
||||
return _undercloud.undercloud_ssh_client()
|
||||
|
||||
def setup_fixture(self):
|
||||
self._inventory_filenames.append(self.get_ansible_inventory_file())
|
||||
super(UndercloudAnsiblePlaybook, self).setup_fixture()
|
||||
|
||||
@staticmethod
|
||||
def get_ansible_inventory_file() -> str:
|
||||
return get_tripleo_ansible_inventory_file()
|
||||
def _ensure_inventory_files(self, *inventory_filenames: str) \
|
||||
-> typing.List[str]:
|
||||
inventory_file = get_tripleo_ansible_inventory_file()
|
||||
if inventory_file is not None:
|
||||
if not os.path.isfile(inventory_file):
|
||||
create_tripleo_inventary_file(inventory_file=inventory_file)
|
||||
inventory_filenames += (inventory_file,)
|
||||
return super()._ensure_inventory_files(*inventory_filenames)
|
||||
|
||||
|
||||
def undercloud_ansible_playbook() -> UndercloudAnsiblePlaybook:
|
||||
|
@ -59,7 +59,7 @@ OPTIONS = [
|
||||
|
||||
# Other options
|
||||
cfg.StrOpt('inventory_file',
|
||||
default='tripleo-hosts.yaml',
|
||||
default='.ansible/inventory/tripleo.yaml',
|
||||
help="path to where to export tripleo inventory file"),
|
||||
|
||||
]
|
||||
@ -75,10 +75,10 @@ def list_options():
|
||||
|
||||
def setup_tobiko_config(conf):
|
||||
# pylint: disable=unused-argument
|
||||
from tobiko.tripleo import ansible
|
||||
from tobiko.tripleo import _ansible
|
||||
from tobiko.tripleo import overcloud
|
||||
from tobiko.tripleo import topology
|
||||
|
||||
ansible.setup_undercloud_ansible_playbook()
|
||||
_ansible.setup_undercloud_ansible_playbook()
|
||||
overcloud.setup_overcloud_keystone_crederntials()
|
||||
topology.setup_tripleo_topology()
|
||||
|
Loading…
Reference in New Issue
Block a user