streda 9. februára 2022

ansible - copy configuration files (dns)

How copy files in ansible? Easy!





ansible + host(s) + -m copy -a "source dest on servers and permissions"


on ansible server is /etc/ansible/resolv.conf - in this server is nameserver 8.8.8.8



there is command to send

 [root@localhost ~]# ansible 10.0.2.5,10.0.2.6  -m copy -a "src=/etc/ansible/resolv.conf dest=/etc/resolv.conf mode=644 owner=root group=root"

10.0.2.5 | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python"

    },

    "changed": false,

    "checksum": "e19182dd3a1465bda3aa2e1a63067bec82dd5ad3",

    "dest": "/etc/resolv.conf",

    "gid": 0,

    "group": "root",

    "mode": "0644",

    "owner": "root",

    "path": "/etc/resolv.conf",

    "secontext": "system_u:object_r:net_conf_t:s0",

    "size": 19,

    "state": "file",

    "uid": 0

}

10.0.2.6 | CHANGED => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python"

    },

    "changed": true,

    "checksum": "e19182dd3a1465bda3aa2e1a63067bec82dd5ad3",

    "dest": "/etc/resolv.conf",

    "gid": 0,

    "group": "root",

    "md5sum": "fe0b86955e4eb444f17f54d086580b1f",

    "mode": "0644",

    "owner": "root",

    "secontext": "system_u:object_r:net_conf_t:s0",

    "size": 19,

    "src": "/root/.ansible/tmp/ansible-tmp-1643144657.809647-201108-123041954281265/source",

    "state": "file",

    "uid": 0


check on the 10.0.2.5 server

ip a s 
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:ca:d5:38 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.5/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 354sec preferred_lft 354sec
    inet6 fe80::a00:27ff:feca:d538/64 scope link
       valid_lft forever preferred_lft forever

[root@localhost ~]# cat /etc/resolv.conf
nameserver 8.8.8.8
[root@localhost ~]#


Žiadne komentáre:

Zverejnenie komentára