<s> import sys , os , stat <EOL> import ansible . playbook <EOL> import ansible . constants as C <EOL> import ansible . utils . template <EOL> from ansible import errors , callbacks , utils <EOL> from ansible . color import ANSIBLE_COLOR , stringc <EOL> from ansible . callbacks import display <EOL> import underwear <EOL> def colorize ( lead , num , color ) : <EOL> """<STR_LIT>""" <EOL> if num != <NUM_LIT:0> and ANSIBLE_COLOR and color is not None : <EOL> return "<STR_LIT>" % ( stringc ( lead , color ) , stringc ( "<STR_LIT:=>" , color ) , stringc ( str ( num ) , color ) ) <EOL> else : <EOL> return "<STR_LIT>" % ( lead , str ( num ) ) <EOL> def hostcolor ( host , stats , color = True ) : <EOL> if ANSIBLE_COLOR and color : <EOL> if stats [ '<STR_LIT>' ] != <NUM_LIT:0> or stats [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> return "<STR_LIT>" % stringc ( host , '<STR_LIT>' ) <EOL> elif stats [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> return "<STR_LIT>" % stringc ( host , '<STR_LIT>' ) <EOL> else : <EOL> return "<STR_LIT>" % stringc ( host , '<STR_LIT>' ) <EOL> return "<STR_LIT>" % host <EOL> def deploy ( args ) : <EOL> parser = utils . base_parser ( <EOL> constants = C , <EOL> usage = "<STR_LIT>" , <EOL> connect_opts = True , <EOL> runas_opts = True , <EOL> subset_opts = True , <EOL> check_opts = True , <EOL> diff_opts = True <EOL> ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = "<STR_LIT>" , action = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , default = [ ] ) <EOL> options , args = parser . parse_args ( args ) <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> parser . print_help ( file = sys . stderr ) <EOL> return <NUM_LIT:1> <EOL> inventory = ansible . inventory . Inventory ( options . inventory ) <EOL> inventory . subset ( options . subset ) <EOL> print "<STR_LIT>" % str ( len ( inventory . list_hosts ( ) ) ) <EOL> if len ( inventory . list_hosts ( ) ) == <NUM_LIT:0> : <EOL> raise errors . AnsibleError ( "<STR_LIT>" ) <EOL> sshpass = None <EOL> sudopass = None <EOL> su_pass = None <EOL> vault_pass = None <EOL> options . ask_pass = options . ask_pass or C . DEFAULT_ASK_PASS <EOL> if options . connection == "<STR_LIT>" : <EOL> options . ask_pass = False <EOL> options . ask_sudo_pass = options . ask_sudo_pass or C . DEFAULT_ASK_SUDO_PASS <EOL> ( sshpass , sudopass , su_pass , vault_pass ) = utils . ask_passwords ( ask_pass = options . ask_pass , <EOL> ask_sudo_pass = options . ask_sudo_pass , ask_su_pass = options . ask_su_pass , <EOL> ask_vault_pass = options . ask_vault_pass ) <EOL> options . sudo_user = options . sudo_user or C . DEFAULT_SUDO_USER <EOL> options . su_user = options . su_user or C . DEFAULT_SU_USER <EOL> extra_vars = { } <EOL> for extra_vars_opt in options . extra_vars : <EOL> if extra_vars_opt . startswith ( "<STR_LIT:@>" ) : <EOL> extra_vars = utils . combine_vars ( extra_vars , utils . parse_yaml_from_file ( extra_vars_opt [ <NUM_LIT:1> : ] ) ) <EOL> elif extra_vars_opt and extra_vars_opt [ <NUM_LIT:0> ] in '<STR_LIT>' : <EOL> extra_vars = utils . combine_vars ( extra_vars , utils . parse_yaml ( extra_vars_opt ) ) <EOL> else : <EOL> extra_vars = utils . combine_vars ( extra_vars , utils . parse_kv ( extra_vars_opt ) ) <EOL> playbook = underwear . __path__ [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> inventory . set_playbook_basedir ( os . path . dirname ( playbook ) ) <EOL> stats = callbacks . AggregateStats ( ) <EOL> playbook_cb = callbacks . PlaybookCallbacks ( verbose = utils . VERBOSITY ) <EOL> runner_cb = callbacks . PlaybookRunnerCallbacks ( stats , <EOL> verbose = utils . VERBOSITY ) <EOL> if not os . path . exists ( playbook ) : <EOL> raise errors . AnsibleError ( "<STR_LIT>" % playbook ) <EOL> if not ( os . path . isfile ( playbook ) or stat . S_ISFIFO ( os . stat ( playbook ) . st_mode ) ) : <EOL> raise errors . AnsibleError ( "<STR_LIT>" % playbook ) <EOL> pb = ansible . playbook . PlayBook ( <EOL> playbook = playbook , <EOL> module_path = options . module_path , <EOL> inventory = inventory , <EOL> forks = options . forks , <EOL> remote_user = options . remote_user , <EOL> remote_pass = sshpass , <EOL> callbacks = playbook_cb , <EOL> runner_callbacks = runner_cb , <EOL> stats = stats , <EOL> timeout = options . timeout , <EOL> transport = options . connection , <EOL> sudo = options . sudo , <EOL> sudo_user = options . sudo_user , <EOL> sudo_pass = sudopass , <EOL> extra_vars = extra_vars , <EOL> private_key_file = options . private_key_file , <EOL> only_tags = [ '<STR_LIT:all>' , ] , <EOL> skip_tags = None , <EOL> check = options . check , <EOL> diff = options . diff <EOL> ) <EOL> failed_hosts = [ ] <EOL> unreachable_hosts = [ ] <EOL> try : <EOL> pb . run ( ) <EOL> hosts = sorted ( pb . stats . processed . keys ( ) ) <EOL> print hosts <EOL> display ( callbacks . banner ( "<STR_LIT>" ) ) <EOL> playbook_cb . on_stats ( pb . stats ) <EOL> for h in hosts : <EOL> t = pb . stats . summarize ( h ) <EOL> if t [ '<STR_LIT>' ] > <NUM_LIT:0> : <EOL> failed_hosts . append ( h ) <EOL> if t [ '<STR_LIT>' ] > <NUM_LIT:0> : <EOL> unreachable_hosts . append ( h ) <EOL> retries = failed_hosts + unreachable_hosts <EOL> if len ( retries ) > <NUM_LIT:0> : <EOL> filename = pb . generate_retry_inventory ( retries ) <EOL> if filename : <EOL> display ( "<STR_LIT>" % filename ) <EOL> for h in hosts : <EOL> t = pb . stats . summarize ( h ) <EOL> display ( "<STR_LIT>" % ( <EOL> hostcolor ( h , t ) , <EOL> colorize ( '<STR_LIT>' , t [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> colorize ( '<STR_LIT>' , t [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> colorize ( '<STR_LIT>' , t [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> colorize ( '<STR_LIT>' , t [ '<STR_LIT>' ] , '<STR_LIT>' ) ) , <EOL> screen_only = True <EOL> ) <EOL> display ( "<STR_LIT>" % ( <EOL> hostcolor ( h , t , False ) , <EOL> colorize ( '<STR_LIT>' , t [ '<STR_LIT>' ] , None ) , <EOL> colorize ( '<STR_LIT>' , t [ '<STR_LIT>' ] , None ) , <EOL> colorize ( '<STR_LIT>' , t [ '<STR_LIT>' ] , None ) , <EOL> colorize ( '<STR_LIT>' , t [ '<STR_LIT>' ] , None ) ) , <EOL> log_only = True <EOL> ) <EOL> print "<STR_LIT>" <EOL> if len ( failed_hosts ) > <NUM_LIT:0> : <EOL> return <NUM_LIT:2> <EOL> if len ( unreachable_hosts ) > <NUM_LIT:0> : <EOL> return <NUM_LIT:3> <EOL> except errors . AnsibleError , e : <EOL> display ( "<STR_LIT>" % e , color = '<STR_LIT>' ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> </s>
