sshd_config or a banner file

Hi,
Today I'm making another go at Ansible. Part of using Ansible is
getting rid of some of the bad decisions the previous administrators
did in the name of "security".

I want to deploy a standard sshd_config file and a /etc/banner

Do I need to create a j2 file to start this process? I'm not setting
a static IP for sshd to listen on, so I don't think I have any
variables. The banner file should be on all machines.

James

Yeah, it’s not required.

You can use the ‘copy’ module instead of the ‘template’ module if you just want to transfer the file directly without any changes.

It works basically the same, without doing any template ops, and you can still specify the mode, user, and other things, just like you can with the file module (and the template module).

–Michael

If the destination file does not exist, do we need to use an option to
state=? I have tried my command with and without state=absent. When I
run it with state=absent I get: 10.54.244.155 | success >> {
    "changed": true,
    "md5sum": "75e1e5d01516c1218752b3238f84b3e7",
    "path": "/etc/banner",
    "state": "absent"

Either way my file doesn't get copied.

Here is the command I used:

ansible CL800Internal -m copy -a
"src=/Users/jmarcus/AnsibleFiles/etc/banner dest=/etc/banner
state=absent" -u jmarcus --ask-sudo-pass

thanks,
James

--Michael

If the destination file does not exist, do we need to use an option to
state=? I have tried my command with and without state=absent. When I

Leaving off state= implies 'present'.

run it with state=absent I get: 10.54.244.155 | success >> {
"changed": true,
"md5sum": "75e1e5d01516c1218752b3238f84b3e7",
"path": "/etc/banner",
"state": "absent"

Either way my file doesn't get copied.

If you are using the file module with state=absent, you are actually asking for the file to be removed.

The copy module actually calls the file module after doing it's thing.

You can leave off the "state=" or put in "state=present", both mean the same thing.

Hi,
So what am I missing?, in the documentation this command seems to say
I can copy a file to multiple servers: ansible atlanta -m copy -a
"src=/etc/hosts dest=/tmp/hosts".

Thanks,
James

--Michael

I ran this command:
sheepchase:~ jmarcus$ ansible CL800 -m copy -a
"src=/Users/jmarcus/AnsibleFiles/etc/banner dest=/etc/banner" -u
jmarcus --ask-sudo-pass

I got this output for all the servers in group, I guess I'm confused
because I think I'm using "copy" correctly.

cl806.DOMAIN.net | FAILED >> {
    "changed": true,
    "failed": true,
    "md5sum": "75e1e5d01516c1218752b3238f84b3e7",
    "msg": "file does not exist, use copy or template module to create",
    "path": "/etc/banner",
    "state": "absent"
}

Thanks,
James

Interesting. It seems like the copy module is not failing and then the file module is yelling at you because the copy module didn’t place it down.

It might be a permissions error of some kind that is not being handled.

The best thing you can do is add debug to the execute_copy function in runner/init.py and
see what’s up.