2012-03-27 04:07:04 +02:00
|
|
|
#!/usr/bin/env python
|
2012-02-23 20:56:14 +01:00
|
|
|
|
2012-02-29 01:08:09 +01:00
|
|
|
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
2012-02-24 01:42:05 +01:00
|
|
|
#
|
2012-02-29 01:08:09 +01:00
|
|
|
# This file is part of Ansible
|
2012-02-24 01:42:05 +01:00
|
|
|
#
|
2012-02-29 01:08:09 +01:00
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2012-02-24 01:42:05 +01:00
|
|
|
#
|
2012-02-29 01:08:09 +01:00
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
2012-02-24 01:42:05 +01:00
|
|
|
|
2012-03-03 03:11:43 +01:00
|
|
|
########################################################
|
2015-05-04 04:47:26 +02:00
|
|
|
from __future__ import (absolute_import)
|
|
|
|
__metaclass__ = type
|
2012-03-03 03:11:43 +01:00
|
|
|
|
2014-12-16 18:20:11 +01:00
|
|
|
__requires__ = ['ansible']
|
|
|
|
try:
|
|
|
|
import pkg_resources
|
|
|
|
except Exception:
|
|
|
|
# Use pkg_resources to find the correct versions of libraries and set
|
|
|
|
# sys.path appropriately when there are multiversion installs. But we
|
|
|
|
# have code that better expresses the errors in the places where the code
|
|
|
|
# is actually used (the deps are optional for many code paths) so we don't
|
|
|
|
# want to fail here.
|
|
|
|
pass
|
|
|
|
|
2014-02-26 17:00:48 +01:00
|
|
|
import os
|
2012-02-28 10:00:31 +01:00
|
|
|
import sys
|
2012-03-18 22:41:44 +01:00
|
|
|
|
2015-05-13 17:15:04 +02:00
|
|
|
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
|
2015-05-04 04:47:26 +02:00
|
|
|
from ansible.utils.display import Display
|
2012-02-28 09:54:41 +01:00
|
|
|
|
2012-03-03 03:11:43 +01:00
|
|
|
########################################################
|
|
|
|
|
2012-02-28 09:54:41 +01:00
|
|
|
if __name__ == '__main__':
|
2013-04-27 16:24:26 +02:00
|
|
|
|
2015-05-04 04:47:26 +02:00
|
|
|
cli = None
|
|
|
|
display = Display()
|
2015-06-09 23:29:46 +02:00
|
|
|
me = os.path.basename(sys.argv[0])
|
2015-05-04 04:47:26 +02:00
|
|
|
|
2012-03-13 04:11:54 +01:00
|
|
|
try:
|
2015-05-04 04:47:26 +02:00
|
|
|
if me == 'ansible-playbook':
|
|
|
|
from ansible.cli.playbook import PlaybookCLI as mycli
|
|
|
|
elif me == 'ansible':
|
|
|
|
from ansible.cli.adhoc import AdHocCLI as mycli
|
|
|
|
elif me == 'ansible-pull':
|
|
|
|
from ansible.cli.pull import PullCLI as mycli
|
|
|
|
elif me == 'ansible-doc':
|
|
|
|
from ansible.cli.doc import DocCLI as mycli
|
|
|
|
elif me == 'ansible-vault':
|
|
|
|
from ansible.cli.vault import VaultCLI as mycli
|
|
|
|
elif me == 'ansible-galaxy':
|
|
|
|
from ansible.cli.galaxy import GalaxyCLI as mycli
|
|
|
|
|
|
|
|
cli = mycli(sys.argv, display=display)
|
|
|
|
if cli:
|
|
|
|
cli.parse()
|
|
|
|
sys.exit(cli.run())
|
|
|
|
else:
|
|
|
|
raise AnsibleError("Program not implemented: %s" % me)
|
2012-03-14 01:59:05 +01:00
|
|
|
|
2015-05-04 04:47:26 +02:00
|
|
|
except AnsibleOptionsError as e:
|
|
|
|
cli.parser.print_help()
|
|
|
|
display.display(str(e), stderr=True, color='red')
|
2015-05-13 17:15:04 +02:00
|
|
|
sys.exit(5)
|
|
|
|
except AnsibleParserError as e:
|
|
|
|
display.display(str(e), stderr=True, color='red')
|
|
|
|
sys.exit(4)
|
|
|
|
# TQM takes care of these, but leaving comment to reserve the exit codes
|
|
|
|
# except AnsibleHostUnreachable as e:
|
|
|
|
# display.display(str(e), stderr=True, color='red')
|
|
|
|
# sys.exit(3)
|
|
|
|
# except AnsibleHostFailed as e:
|
|
|
|
# display.display(str(e), stderr=True, color='red')
|
|
|
|
# sys.exit(2)
|
2015-05-04 04:47:26 +02:00
|
|
|
except AnsibleError as e:
|
|
|
|
display.display(str(e), stderr=True, color='red')
|
2015-05-13 17:15:04 +02:00
|
|
|
sys.exit(1)
|
2015-05-04 04:47:26 +02:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
display.error("interrupted")
|
2015-05-13 17:15:04 +02:00
|
|
|
sys.exit(99)
|