@ -61,6 +61,7 @@ from ansible.template import Templar
from ansible . utils . collection_loader import AnsibleCollectionConfig
from ansible . utils . collection_loader import AnsibleCollectionConfig
from ansible . utils . display import Display
from ansible . utils . display import Display
from ansible . utils . plugin_docs import get_versioned_doclink
from ansible . utils . plugin_docs import get_versioned_doclink
from ansible . utils . vars import load_extra_vars
display = Display ( )
display = Display ( )
urlparse = six . moves . urllib . parse . urlparse
urlparse = six . moves . urllib . parse . urlparse
@ -366,6 +367,7 @@ class GalaxyCLI(CLI):
init_parser . add_argument ( ' --type ' , dest = ' role_type ' , action = ' store ' , default = ' default ' ,
init_parser . add_argument ( ' --type ' , dest = ' role_type ' , action = ' store ' , default = ' default ' ,
help = " Initialize using an alternate role type. Valid types include: ' container ' , "
help = " Initialize using an alternate role type. Valid types include: ' container ' , "
" ' apb ' and ' network ' . " )
" ' apb ' and ' network ' . " )
opt_help . add_runtask_options ( init_parser )
def add_remove_options ( self , parser , parents = None ) :
def add_remove_options ( self , parser , parents = None ) :
remove_parser = parser . add_parser ( ' remove ' , parents = parents , help = ' Delete roles from roles_path. ' )
remove_parser = parser . add_parser ( ' remove ' , parents = parents , help = ' Delete roles from roles_path. ' )
@ -1171,6 +1173,7 @@ class GalaxyCLI(CLI):
)
)
loader = DataLoader ( )
loader = DataLoader ( )
inject_data . update ( load_extra_vars ( loader ) )
templar = Templar ( loader , variables = inject_data )
templar = Templar ( loader , variables = inject_data )
# create role directory
# create role directory
@ -1214,7 +1217,11 @@ class GalaxyCLI(CLI):
src_template = os . path . join ( root , f )
src_template = os . path . join ( root , f )
dest_file = os . path . join ( obj_path , rel_root , filename )
dest_file = os . path . join ( obj_path , rel_root , filename )
template_data = to_text ( loader . _get_file_contents ( src_template ) [ 0 ] , errors = ' surrogate_or_strict ' )
template_data = to_text ( loader . _get_file_contents ( src_template ) [ 0 ] , errors = ' surrogate_or_strict ' )
b_rendered = to_bytes ( templar . template ( template_data ) , errors = ' surrogate_or_strict ' )
try :
b_rendered = to_bytes ( templar . template ( template_data ) , errors = ' surrogate_or_strict ' )
except AnsibleError as e :
shutil . rmtree ( b_obj_path )
raise AnsibleError ( f " Failed to create { galaxy_type . title ( ) } { obj_name } . Templating { src_template } failed with the error: { e } " ) from e
with open ( dest_file , ' wb ' ) as df :
with open ( dest_file , ' wb ' ) as df :
df . write ( b_rendered )
df . write ( b_rendered )
else :
else :