@@ -20,6 +20,7 @@ def run(self, tmp=None, task_vars=None):
2020 'path' : {'type' : 'path' , 'required' : True },
2121 'state' : {'type' : 'str' , 'choices' : ['present' , 'absent' , 'file' ], 'default' : 'present' },
2222 'content' : {'type' : 'str' },
23+ 'file' : {'type' : 'path' },
2324 'template' : {'type' : 'path' },
2425 'vars' : {'type' : 'dict' , 'default' : {}},
2526 'user' : {'type' : 'str' },
@@ -28,7 +29,7 @@ def run(self, tmp=None, task_vars=None):
2829 'validate' : {'type' : 'str' },
2930 },
3031 mutually_exclusive = (
31- ['content' , 'template' ],
32+ ['content' , 'file' , ' template' ],
3233 ),
3334 )
3435
@@ -66,6 +67,28 @@ def run(self, tmp=None, task_vars=None):
6667 shared_loader_obj = self ._shared_loader_obj ,
6768 ).run (task_vars = combine_vars (task_vars , args ['vars' ]))
6869 )
70+ elif (args ['state' ] in ['present' , 'file' ]) and args ['file' ]:
71+ display .v ('Use "ansible.builtin.copy" to ensure "%s" file.' % args ['path' ])
72+ task = self ._task .copy ()
73+ task .args = {
74+ 'dest' : args ['path' ],
75+ 'src' : args ['file' ],
76+ 'owner' : args ['user' ],
77+ 'group' : args ['group' ],
78+ 'mode' : args ['mode' ],
79+ 'validate' : args ['validate' ],
80+ }
81+ result .update (
82+ self ._shared_loader_obj .action_loader .get (
83+ 'ansible.builtin.copy' ,
84+ task = task ,
85+ connection = self ._connection ,
86+ play_context = self ._play_context ,
87+ loader = self ._loader ,
88+ templar = self ._templar ,
89+ shared_loader_obj = self ._shared_loader_obj ,
90+ ).run (task_vars = task_vars )
91+ )
6992 elif (args ['state' ] in ['present' , 'file' ]) and args ['template' ]:
7093 display .v ('Use "ansible.builtin.template" to ensure "%s" template.' % args ['path' ])
7194 task = self ._task .copy ()
@@ -89,7 +112,7 @@ def run(self, tmp=None, task_vars=None):
89112 ).run (task_vars = combine_vars (task_vars , args ['vars' ]))
90113 )
91114 elif args ['state' ] == 'file' :
92- raise AnsibleActionFail ('one of the following is required: content, template' )
115+ raise AnsibleActionFail ('one of the following is required: content, file, template' )
93116 elif args ['state' ] == 'present' :
94117 display .v ('Use "ansible.builtin.file" to ensure "%s" is a directory.' % args ['path' ])
95118 result .update (
0 commit comments