===============================================================
How to Copy file from remote server to local Anisble server
===============================================================
Let`s take backup of ens33 network configuration file on ansible server
Following file is on ansible web client
[root@web1 network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO="static"
NAME=ens33
UUID=0ca5a92f-d841-4f82-a69b-56c6a52657e5
IPADDR="192.168.159.142"
NETMASK="255.255.255.0"
GATEWAY="192.168.159.2"
DEVICE=ens33
ONBOOT=yes
[root@web1 network-scripts]#
====================================================================================================
Now lets write playbook which will copy file from web1 ansible client to ansible server localy
====================================================================================================
[root@ansimaster playbooks]# cat fetchremotefile.yml
- hosts: webservers
tasks:
- name: Ansible fetch files from remote server to the local machine under /tmp/web1/ using Ansible fetch module
fetch:
src: /etc/sysconfig/network-scripts/ifcfg-ens33
dest: /tmp/web1/
[root@ansimaster playbooks]#
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook -v fetchremotefile.yml --syntax-check
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
playbook: fetchremotefile.yml
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook -v fetchremotefile.yml
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
PLAY [webservers] **********************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]
TASK [Ansible fetch files from remote server to the local machine under /tmp/web1/ using Ansible fetch module] **********************
ok: [192.168.159.142] => {"changed": false, "checksum": "9fdc4631156b259899e953b5f404210da39ca1cb", "dest": "/tmp/web1/192.168.159.142/etc/sysconfig/network-scripts/ifcfg-ens33", "file": "/etc/sysconfig/network-scripts/ifcfg-ens33", "md5sum": "1d434556162da86401f9945f74fd4929"}
PLAY RECAP *****************************************************************************************************************************
192.168.159.142 : ok=2 changed=0 unreachable=0 failed=0
[root@ansimaster playbooks]#
=====================================================================================================================
Now check network configuration file of web1 client should preset on ansible server under /tmp/web1/
=====================================================================================================================
[root@ansimaster ~]# ls -ld /tmp/web1
drwxr-xr-x. 3 root root 29 May 22 09:25 /tmp/web1
[root@ansimaster ~]#
[root@ansimaster network-scripts]# cat /tmp/web1/192.168.159.142/etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO="static"
NAME=ens33
UUID=0ca5a92f-d841-4f82-a69b-56c6a52657e5
IPADDR="192.168.159.142"
NETMASK="255.255.255.0"
GATEWAY="192.168.159.2"
DEVICE=ens33
ONBOOT=yes
[root@ansimaster network-scripts]#
How to Copy file from remote server to local Anisble server
===============================================================
Let`s take backup of ens33 network configuration file on ansible server
Following file is on ansible web client
[root@web1 network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO="static"
NAME=ens33
UUID=0ca5a92f-d841-4f82-a69b-56c6a52657e5
IPADDR="192.168.159.142"
NETMASK="255.255.255.0"
GATEWAY="192.168.159.2"
DEVICE=ens33
ONBOOT=yes
[root@web1 network-scripts]#
====================================================================================================
Now lets write playbook which will copy file from web1 ansible client to ansible server localy
====================================================================================================
[root@ansimaster playbooks]# cat fetchremotefile.yml
- hosts: webservers
tasks:
- name: Ansible fetch files from remote server to the local machine under /tmp/web1/ using Ansible fetch module
fetch:
src: /etc/sysconfig/network-scripts/ifcfg-ens33
dest: /tmp/web1/
[root@ansimaster playbooks]#
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook -v fetchremotefile.yml --syntax-check
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
playbook: fetchremotefile.yml
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook -v fetchremotefile.yml
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
PLAY [webservers] **********************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]
TASK [Ansible fetch files from remote server to the local machine under /tmp/web1/ using Ansible fetch module] **********************
ok: [192.168.159.142] => {"changed": false, "checksum": "9fdc4631156b259899e953b5f404210da39ca1cb", "dest": "/tmp/web1/192.168.159.142/etc/sysconfig/network-scripts/ifcfg-ens33", "file": "/etc/sysconfig/network-scripts/ifcfg-ens33", "md5sum": "1d434556162da86401f9945f74fd4929"}
PLAY RECAP *****************************************************************************************************************************
192.168.159.142 : ok=2 changed=0 unreachable=0 failed=0
[root@ansimaster playbooks]#
=====================================================================================================================
Now check network configuration file of web1 client should preset on ansible server under /tmp/web1/
=====================================================================================================================
[root@ansimaster ~]# ls -ld /tmp/web1
drwxr-xr-x. 3 root root 29 May 22 09:25 /tmp/web1
[root@ansimaster ~]#
[root@ansimaster network-scripts]# cat /tmp/web1/192.168.159.142/etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO="static"
NAME=ens33
UUID=0ca5a92f-d841-4f82-a69b-56c6a52657e5
IPADDR="192.168.159.142"
NETMASK="255.255.255.0"
GATEWAY="192.168.159.2"
DEVICE=ens33
ONBOOT=yes
[root@ansimaster network-scripts]#
No comments:
Post a Comment