You are reading the article Learn How Untar Works In Ansible With Examples updated in December 2023 on the website Kientrucdochoi.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Learn How Untar Works In Ansible With Examples
Introduction to Ansible untarAnsible untar module also known as unarchive for Unix OS or win_zip for the windows operating system is used to extract or unpack the archive files or folders on the remote destination by copying the archive file first by default on the remote server and also supports many parameters to deal with the unarchive or win_zip functionality like the owner, dest, exclude and more.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
SyntaxFor the non-windows target unarchive or ansible.builtin.unarchive command uses the below syntax. We have shown the basics parameters
Parameters:
copy: No / Yes (Default)
The default Option is Yes and it copies the files from the local controller to the remote host if specified yes or nothing specified. For working with the remote source need to specify the remote_src and this copy parameter is not helpful there.
src (required):
Source path of the file. If remote_src is ‘yes’ then the source path would be on the remote location otherwise the source path is on the local controller node.
dest (required):
Remote server absolute path where the archive is going to extract.
remote_src: no (Default) / yes
If set ‘yes’ specifies that the source archive path is on the remote computer. For the ‘no’ value the path is on the local controller node.
owner:
name of the user that should own the files/directory after unpack and same replicates (added) to the chown.
group:
Name of the group that should own the files/directory and same replicates (added) to the chown.
exclude:
List of files or directories that need to be excluded from the unpacking.
include:
List of files or directories that need to be included in the unpacking process.
keep_newer: no (default) / yes
If set yes, it replaces the existing files that are newer than the files inside the archive.
mode:
Permissions that the files or directories should have after unpacked (like 644, 777, etc).
For the windows target src, dest, creates parameters remain the same as unarchive module and the additional parameters are as below.
Parameters:
delete_archive: no (default) / yes
Removes the zip file after unzipping.
password
If the Zip file is password encrypted then this parameter is useful and it requires the PSCX module to be installed.
recurse: no (default) / yes
recursively expands the zip file within the src directory.
Setting value ‘yes’ requires the PSCX module to be installed.
Please note: the win_unzip module doesn’t use the remote_src parameter.
How untar works in Ansible?Ansible unarchive module for non-windows target comes with the ansible-base and so it is included in the Ansible installations. For the windows target, we need to use the win_unzip module. If the module is not available then you can download it from the galaxy.
ansible-galaxy collection install community.windows
Below is the simple playbook for windows untar (unzip).
dest: c:temp7zipInstaller
Output:
The above playbook will unzip the file from the source location to the destination remote servers. If the destination path doesn’t exist it creates the destination path.
You must have noticed here, although the source path is remote, we don’t need to use remote_src because the win_unzip module doesn’t support it and when we use the remote source path for the non-target windows server we must specify the remote_src. For example,
remote_src: yes
ExamplesHere are the following examples mention below
Example #1 – unarchive module task for UNIX os.dest: /tmp/phyes
In this playbook, it will retrieve the chúng tôi file to the destination remote host /tmp/phyes. Before running this task unlike the win_unzip module, you need to make sure that the destination path exists otherwise it will throw an error.
Output:
Example #2 – Exclude files from the archive.To exclude the certain file from the unpacking we can use h
Code:
exclude: ’Test1 document.txt’
If there are multiple files to exclude then you can provide the list as below.
- ’sourcefile.py’
Example #3 – Include files from the archiveCode:
include: ’Test1 document.txt’
The above playbook will include only the test1 text file and to include the multiple documents, use the below command.
- ’sourcefile.py’
Example #4 – using multiple parameters together.Code:
owner: ansibleadmin
In the above playbook, it will include only 2 files, keep_newer parameter will not replace the existing files that are newer than files from the archive, remote_src indicates the remote source and it will set the owner permission on the files and it will keep the file permission 0644.
ConclusionUntar or unarchive or unzip modules are very useful when we write the playbook. It makes it easier to extract the files or folders on the destination server without using any third-party software and in addition, it uses various parameters like we don’t need to copy the file before extracting, adding permissions after extract, etc.
Recommended ArticlesThis is a guide to Ansible untar. Here we discuss How untar works in Ansible and Examples along with the codes and outputs. You may also look at the following articles to learn more –
You're reading Learn How Untar Works In Ansible With Examples
How Xml Works In Ansible?
Definition
Ansible XML module, which is a part of the General ansible collection module and it supports the various parameters (described in the syntax section) to read the content of the XML file, add or remove the child elements or values, print the specific child attributes or the nodes, change the attribute values, etc. by providing the correct xpath syntax.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax;
For the non-windows target, ansible uses the module syntax community.general.xml, and for the windows target, ansible uses the win_xml module.
Parameters supported by the chúng tôi module.
Parameters:
add_children:
attribute:
The attribute to select when using the parameter value.
This is a string and not pretended with @.
backup:
choices: no (default) / yes
Create the backup file, including the timestamp of the backup. This module doesn’t take the backup automatically; we need to set the backup parameter to yes.
content: attribute/text
choices: attribute / text
count:
choices: no (default) / yes
Search for the given XPath and provide the count of any matches.
input_type:
choices: xml / yaml (default)
Type of the input for the add_children and set_children.
insertafter:
choices: no (default) / yes
It adds the additional child element(s) after the last element given in the Xpath.
Insertbefore:
choices: no (default) / yes
It adds the additional child element(s) before the first element given in the Xpath.
pretty_print:
choices: no (default) / yes
Pretty print xml output.
print_match:
choice: no (default) / yes
Search for the given Xpath and print any output that matches.
path:
aliases: dest / file
Path of the XML file as an input. If the XML string is not specified, then the path is required.
set_children:
To set the child element of the selected element from the given xpath.
state:
choices: absent/present
alias: ensure
Set or remove an xpath selection (node(s), attributes(s)).
value:
Desired state of the selected attribute.
xmlstring:
A string containing xml on which to operate. This parameter is necessary if the path is not provided.
xpath:
A valid xpath expression to describe the item(s) to manipulate, and it operates on the document root (/) by default.
How XML works in Ansible?To deal with the XML files, we need the ansible XML module, and it doesn’t come with the ansible default installation, but we need to install it. It is available as a part of the Ansible community.
To install the XML module, we can use the below command. This will install the XML for both the Unix and the Windows operating systems.
ansible-galaxy collection install community.general
For the Windows operating system, you can use the win_xml module, and for the non-windows target, you can use the chúng tôi module
When you work with the XML file, you need to provide the xPath to deal with the XML attributes and the values. You can learn more about the xPath notations from the websites below.
There are also many other websites you can refer to. For this example, we will use the sample XML file from Microsoft.
Playbook example:
ExamplesLet us discuss examples of Ansible XML.
Example #1: Ansible XML module to count the number of attribute nodesIn this playbook, we will count the total number of author nodes.
Output:
There are a total of 12 “author” nodes.
Example #2: Remove the specific node with the attribute valueThis playbook will remove all the nodes with the book id attribute bk101.
xpath: /catalog/book[@id=’bk101′] state: absent
Output:
Example #3: Playbook to remove attributesThis playbook will remove all the matching attributes. In this case, it will remove the ID attribute.
state: absent
Output:
Once you check the XML output, all the ids will be removed.
Example #4: Adding the new element with the valueThis playbook will add the new element “Newbook” with the value “fiction”.
value: ’Fiction’
Output:
Example #5: Playbook to change the attribute valuevalue: ’ComputerTech’
Output:
XML file output:
Example #6: Ansible playbook to add multiple child elementsThis playbook will add the multiple child elements to the specified attributes of the book node.
xpath: /catalog/book[@id=’bk101′] - tag: ’1001′
Output:
XML file output:
If you need to insert before the specific element, then use the insertbefore parameter. For example,
xpath: /catalog/book[@id=’bk101′]/genre[text() = ”Computer”] - tag: ’1001′
XML Output:
And for the insert after some attribute, you need to specify insertafter parameter.
- tag: ’1001′
ConclusionXML file is used by the various websites, software, configurations, etc. and ansible uses the various parameters to read the content, copy the XML file, manipulate the XML file as per the requirement which helps when you configure any website or software using XML then you can use the builtin plugin to work with the XML file.
Recommended ArticlesThis is a guide to Ansible XML. Here we discuss the Definition, syntax, parameters, How XML works in Ansible? with Examples with code implementation. You may also have a look at the following articles to learn more –
How Php Ucwords() Works With Examples
Introduction to PHP ucwords()
Ucwords() in PHP is a built-in function. It is helpful to convert the first and foremost character of a string into uppercase. The ucwords() only supports PHP 4 & above versions. ucwords() function takes a string as an input value and it outputs the string by changing the first letter/character of the string into uppercase. Other than this every other character remains the same as the previous time. The ucwords() function in PHP returns converted to string by changing the first letter of all words to uppercase.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax Ucwords($string, $separator)The ucwords() syntax accepts just two parameters.
1. $string( string mandatory ): Between the parenthesis of ucwords() function, string input is required. It is a must and mandatory to this function declaration in order to specify the string which is to be converted.
2. $separator ( Optional Parameter ): Separator is the optional parameter of ucwords() function. It contains words separator characters. The separator used in the input string for the words. The listed characters which are listed below are by default:
t for tab
Space
r for Carriage return
n for newline
v for vertical tab
f for form feed
$Separator parameter added in 5.5.16, 5.4.32 versions of PHP.
How PHP ucwords() works?PHP ucwords works when the text/words contain mixed types of letters/characters inside words. Only the first character of the word/ first characters of all the words which are in the sentence will be converted to capital letters. It works using a string value that contains word/words and it also uses one separator/delimiter value but it is optional. No issue with the separator variable.
Examples of PHP ucwords()Given below are the examples
Example #1How the basic program works by using ucwords() PHP function.
Code:
<?php $input_string = "hey buddy, pavan sake is coming just wait."; echo "Before:". $input_string; $result_string = ucwords($input_string); echo "After: ".$result_string;Output:
Example #2Code:
<?php $result_string1 = ucwords($input_string); echo $result_string2;Output:
Example #3This example here is to use ucwords() function on arrays which has a list of names/strings by removing delimeters/parameters “–“ and “”.
Code:
<?php function ucname($string1) { $string1 =ucwords(strtolower($string1)); foreach (array('-', ''') as $parameters1) { if (strpos($string1, $parameters1)!==false) { $string1 =implode($parameters1, array_map('ucfirst', explode($parameters1, $string1))); } } return $string1; } <?php $names1 =array( 'SAKE-PAVAN KUMAR', 'ANIL O'KUMAR', 'MARUTHI PRASAD', 'surendra la gandham', 'rAjAsEkHaR KAtUbaDi' ); /* Sake-Pavan Kumar Anil O'Kumar Maruthi Prasad Surendra La Gandham Rajasekhar Kattubadi */Output:
Example #4This is one of the sample programs of ucwords function.
This program has features like:
Multibyte/bytes Compatability
It handles delimiters even if there are multiple
Code:
<?php function ucwords_specific1 ($string1, $delimiters1 = '', $encoding1 = NULL) { if ($encoding1 === NULL) { $encoding1 = mb_internal_encoding();} if (is_string($delimiters1)) { $delimiters1 = str_split( str_replace(' ', '', $delimiters1)); } $delimiters_pattern11 = array(); $delimiters_replace11 = array(); $delimiters_pattern21 = array(); $delimiters_replace21 = array(); foreach ($delimiters1 as $delimiter1) { $uniqid1 = uniqid(); $delimiters_pattern11[] = '/'. preg_quote($delimiter1) .'/'; $delimiters_replace11[] = $delimiter1.$uniqid1.' '; $delimiters_pattern21[] = '/'. preg_quote($delimiter1.$uniqid1.' ') .'/'; $delimiters_replace21[] = $delimiter1; } $return_string1 = $string1; $return_string1 = preg_replace($delimiters_pattern11, $delimiters_replace11, $return_string1); $words1 = explode(' ', $return_string1); { $words1[$index1] = mb_strtoupper(mb_substr($word1, 0, 1, $encoding1), $encoding1).mb_substr($word1, 1, mb_strlen($word1, $encoding1), $encoding1); } $return_string1 = implode(' ', $words1); $return_string1 = preg_replace($delimiters_pattern21, $delimiters_replace21, $return_string1); return $return_string1; } <?php mb_internal_encoding('UTF-8'); $string1 = "PAVAN KUMAR-SAKE d'alltechscience şŠ-òÀ-éÌ hello - web"; echo ucwords_specific1( mb_strtolower($string1, 'UTF-8'), "-'");Output:
The main parameters which are involved in the above program are $string1, $delimeter1, $delimiters, encoding. Delimeter/Delimeters are the parameters that are an option but needed In the development. The string is the parameter that is to be converted. The encoding parameter is to know the character encoding. Internal characters encoding value/values will be used if the parameter don’t omits.
Example #5Code:
<?php $title1 = 'PAVAN "THE KING" SAKE - (I WANT TO BE YOUR) SERVANT'; echo ucwords(strtolower($title1)); <?php function my_ucwords($string1) { $noletters1='"([/'; for($i=0; $i<strlen($noletters1); $i++) $string1 = str_replace($noletters1[$i], $noletters1[$i].' ', $string1); $string1=ucwords($string1); for($i=0; $i<strlen($noletters1); $i++) $string1 = str_replace($noletters1[$i].' ', $noletters1[$i], $string1); return $string1; } $title1 = 'PAVAN "THE KING" SAKE - (I WANT TO BE YOUR) SERVANT'; echo my_ucwords(strtolower($title1));Output:
Example #6This is the example of the code below which will convert all your words into small letters except the first letter. They will be a capital letter. Here ucfirst() function is used. It is also a part of ucwords() function.
Code:
<?php $text1 = "What Buddy ? No 'parameters',shit! "happening" chúng tôi solves many problems now???"; for ($i = 0; $i < count($data1[0]); $i++) { $data1[0][$i] = ucfirst($data1[0][$i]); } $text1 = implode("", $data1[0]); print $text1;Output:
The above program’s output contains the same text which is under $text1 variable but just the first characters of the words which are listed in the variable will be changed to the capital letters remaining ones will remain as small letters.
Recommended Articles
This has been a guide to PHP ucwords(). Here we discuss syntax, parameters, and examples of PHP ucwords(). you may also have a look at the following articles to learn more –
Guide To How Ansible Debug Work With Examples
Introduction to Ansible Debug
In Ansible, when we create and run playbooks, it’s very common that we run into an error due to some issues with our playbook. This can be a syntax error, a logical error or some mandatory parameter is missing. So, this is very important that we should always write our playbook in such have a way that it always prints enough information, be it successful or failure. In Ansible, a module named debug is the requirement when you need to debug and when you need more information in playbook execution output.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
In this article we will try to learn some concepts and see Ansible debug examples. This is a default module that comes with Ansible package. This module prints statements and variable’s values when executing playbooks. This can be very helpful in cases, where you can skip some erratic tasks in the playbook and don’t want to stop it altogether. Using debug in all the erratic tasks, will provide you enough information about the data execution in those tasks and all variables used in such tasks. This will help in troubleshooting and is very useful if you use it with registered variables. We will explore such cases in the example section.
How do Ansible Debug works?In Ansible debug module comes with some parameters and these parameters accept some options. This is given below:
msg: – This parameter accepts strings as inputs. This is used to print a customized message. If no message is given, then a generic message like “Hello World!” is
var: – This accepts strings as input and this is the variable that has been set either by Ansible facts or by the playbook. Also, the values written here will be having implicit double interpolation, as this option runs in the jinja2 context. So, you don’t need to use jinja2 delimiter unless you want to print double interpolation as well. You can use double interpolation when you print a variable in a
verbosity: – This has default as 0. This parameter is used to control when debug is in a run. For example if value 3 is given then debug will only run if -v or above is given while running the playbook.
Examples to Implement Ansible DebugNow we will take some examples, but before going there, we first understand our lab used for testing purposes. Here we have an Ansible control server named ansible-controller and two remotes hosts named host- one and host-two. We will create playbooks and run Ansible commands on the ansible-controller node and manage the users on remote hosts.
Examples #1To print a default message on the output of running a playbook via ansible-playbook, we can create a simple playbook like below:
Code:
name: Here we use Ansible debug debug:
Output:
ansible-playbook debug_dafault_msg.yml
Example #2To print the value of a variable that was defined in the same playbook. we can create a simple playbook like below:
Code:
var: fruit
Output:
ansible-playbook debug_print_var.yml
Example #3To print an Ansible fact of remote hosts, we can create a simple playbook like
Code:
Output:
ansible-playbook debug_ansible_fact.yml
Example #4To print a customized message on the screen, Write a playbook like below:
Code:
msg: “This is machine is {{ ansible_hostname }} with IP {{ ansible_default_ipv4.address }}”
Output:
ansible-playbook debug_with_customized_msg.yml
Example #5You can register the output of a task in a variable and as we know the values of these variables will be stored in JSON format. So, you can call that variable later in the same playbook. To test this or to test which value will be used when we call registered variables. We can use debug like below, creating a playbook.
Code:
Output:
ansible-playbook debug_register_values.yml
Example #6Controlling Verbosity is done by giving values against parameter verbosity and then mentioning the same or more number of –v while running the playbook. Like the playbook in previous. Where we didn’t define any verbosity, then by default it ran with 0 verbosity level. But if define the verbosity level like below:
Code:
var: free_mem.stdout_lines verbosity: 1
Output:
ansible-playbook debug_register_values.yml -v
ConclusionAnsible debug module is a very helpful tool for playbook developers and for administrators who work on need to update a playbook frequently on per need basis. Also, while working in a team where others also have the same stakes as you, using the debug module to add more information is always beneficial and can avoid confusion and dependencies.
Recommended ArticlesThis is a guide to Ansible Debug. Here we discuss an introduction to Ansible Debug, how does it work with examples. You can also go through our other related articles to learn more –
How Does Mongodb Unique Works With Examples
Introduction to MongoDB Unique
MongoDB’s Unique Constraint makes certain that the fields indexed in it, do not store duplicate values for the same field, i.e., making sure the uniqueness of fields. By default, MongoDB enforces this unique constraint on the “_id” field, while inserting new data. One of the major responsibilities is to ensure no duplicate data has been stored in a single key. We also have restrictions here, like MongoDB will be unable to establish a unique index on any specific field, in case if the collection somehow has already stored any data that would breach the feature of unique constraint for the index.
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
Syntax:
Now that we have understood what Unique Constraint in MongoDB, let us learn the standard syntax to write this Unique method.
db.collection_name.createIndex( {field_name : 1} , {unqiue : true} )
How UNIQUE Constraint works in MongoDB?The Unique Index allows the insertion and storing of the values in a document into a collection IF there is no other document in the same collection with the same index key and value. The unique constraint can be implemented on compound indexes. This helps MongoDB to implement uniqueness when combining the index key values. Unique Constraint over separate multiple documents is possible in MongoDB, and it is an essential function in avoiding storing of same values for the indexed key in a different document.
Unique Constraint in MongoDB will allow only a single document with the same value for the indexed key. If we attempt to insert the same value for a single indexed key, it will result in an error.
Query #1
db.code.find()
This returns every document in the collection.
Query #2
db.code.insert( { name:”kumar”, city:“Pune”, code:19 } )
This is an attempt to insert a record with the same code.
Code:
db.code.find()
Output:
Explanation: Here, we have implemented the unique index for “code” key, and so when we try to store a document with existing code, it results in “duplicate key error”.
Unique Constraint for Null ValueWhen we store any document, we store values for the respective keys, and it is stored as per indexing. But in case, if we attempt to store a document that has no specific value or data for a key, for any uncertain key, the document will be stored, and the empty value will be stored as a null value in that document. In MongoDB, only on the document is allowed to be stored with a single index field missing.
Examples to Implement UNIQUE Constraint in MongoDBImplementing Unique Contraint on separate documents to not store the same value for the indexes key, in two different documents.
Example #1We will attempt to insert and store documents with duplicate values. We have a collection named educba, which we will check with find method: db.educba.find()
Code:
db.educba.find()
Output:
As you can see in the above image, we have a collection named educba, and the document has one default unique “_id” and two more keys. We will now implement the unique constraint on the “Name”, which will make it unique, duplicate insertion proof.
Code:
db.educba.createIndex( { “Name” : 1 } , { unique : true } )
Output:
Code:
db.educba.insert({ Name : "Sulaksh" , City : "Pune" })
Output:
First Query:db.educba.insert({ Name : "Sulaksh" , City : "Pune" })
The above query will be successfully inserted. Then we attempted to insert the same query, i.e. same document with the same values, but it resulted in an error that states, “terms”: “E11000 duplicate key error collection: test.educba index: Name_1 dup key: { : ”Sulaksh” }””. This makes our unique constraint applied over the Name field successfully.
Example #2Code:
db.educba.createIndex( {email : 1},{unique : true} )
Output:
We will not attempt to insert a document with a different name but an email id that already exists in another document. Expectations are that the insertion operation will not work and through us an error of duplicate value. We have another document with a slightly different name: Sanket1, for the test purpose, and now we will attempt to update the document with an email: [email protected]
Code:
db.educba.update( { “Name” : ”Sanket1” } , { $set : {email : “[email protected]” }})
Above query will aim to search a record with Name: Sanket1 and will update the record with adding an email id to the document, here $set will add a field for the document.
Output:
As you can see in the above screenshot, when we attempted to update a record with the different Name field, the email was the same as one existing document. It threw us a write error, which means an error occurred while writing the document. The error states “duplicate key error collection: test. educba index: email_1 dup key”. The error points to the issue and makes things clear for us to understand. Like in our case, the email with the value of “[email protected]” is duplicated, already stored, so it will not store again due to unique indexing on the email field. In case you want to know, I’ve used the update with $get to add another field for existing records.
Use Case for this example: Is the New User Registration where we have to ensure that a single mail id is not used to create multiple accounts.
ConclusionImplementing Unique Constraint will restrict the database from storing duplicate values for the same indexed key to wrap it up. This feature helps in storing documents with uniqueness. We learned and understood the syntax followed by the working of it. Then we implemented the unique constraint with example and understood the same along with screenshots, respectively.
Recommended ArticlesThis is a guide to MongoDB Unique. Here we discuss an introduction, how does Unique works and examples for better understanding. You can also go through our other related articles to learn more –
Guide On How Does Ansible Synchronize Works
Introduction to Ansible Synchronize
Web development, programming languages, Software testing & others
Explaining the Ansible SynchronizeAnsible synchronizes work like rsync in many ways. But we must remember the below points while using it in our environments. These will explain this module and show its limitations:
To work with this module, rsync must be installed on both source and target systems.
By default, the source of files is localhost i.e. the controller machine and destination of files is the machine where the connection is made to transfer files. This default feature can be changed by using parameter delegate_to, which allows you to change your source from localhost to some other host. Thus you can copy files from a remote machine to another remote machine.
On synchronize source machine, file’s permissions are of the user who is running the tasks on localhost or remote_user in the case when delegate_to is used.
On synchronize destination machine, the file’s permission will be of remote_user on destination host or of become_user if become=yes is given in parameters, but to elevate the permission, password less sudo should be set up, as rsync itself does not give a way to pass sudo credentials.
Currently, we have only below few connection types to work with Ansible synchronize viz are ssh, paramiko, local, and docker.
Always give the full path of the destination host location, as there may be cases where you used sudo, but files will be copied to remote_user home directory.
Linux rsync limitations related to hard links are also applied here.
Ansible synchronizes module forces -delay-updates to avoid the broken state in case of connection failure.
How does Ansible Synchronize Works?Ansible synchronize user below parameters and their acceptable values are listed as below. Using the combination of these parameters, we can decide the behavior and output of Ansible synchronize.
archive: The acceptable values are yes and no. The default value is set to yes. This mirrors the rsync flag, enable recursive, links, perm, group, owner, time flag.
hecksum: The acceptable values are yes and no. The default value is set to no. This is used to skip based on checksum.
compress: The acceptable values are yes and no. The default value is set to yes. This is used to compress files during transfer to speed up the transfer.
copy_links: The acceptable values are yes and no. The default value is set to no. This is used to copy the referenced items rather than links.
delete: The acceptable values are yes and no. The default value is set to no. This is used to delete files in dest location, which does not exist on the source somehow when the transfer is completed. This works when recursive=yes is set.
dest: The absolute or relative path on the destination machine. Which will be synced from the source.
src: The absolute or relative path on the source machine. Which will be synced from the destination.
dirs: The acceptable values are yes and no. The default value is set to no. This is used to transfer directories without recursive.
dest_port: Port number of ssh on destination.
link_dest: Default value is null. This is used to add a destination to hard links against during the rsync.
links: This is used to copy syslinks as syslinks, not referenced items.
mode: Acceptable values are push and pull. The default value is push.
owner: The acceptable values are yes and no. This is used to preserve owner.
rsync_path: This is used to specify the rsync command path on remote hosts.
times: To preserve the modification times. The acceptable values are yes and no.
Examples of Ansible SynchronizeNow by using examples, we will try to learn about Ansible synchronize, which you might have to use in day to day operations. We will take some examples, but before going there, we first understand our lab, we used for testing purpose. Here we have an Ansible control server named ansible-controller and few remote hosts named host- remote, host-one, and host-two. We will create playbooks and run Ansible commands on the ansible- controller node and see the results on the remote hosts.
In this example, we will do the synchronization of files from source machine viz. Ansible controller node to the remote host. We have a set of files under /var/tmp/sync_folder on the Ansible controller node which will be transferred to remote host via Ansible synchronize module. For this we have a playbook like below:
src: /var/tmp/sync_folder dest: /var/tmp/
ansible-playbook ansible_synchronize.yaml
ls -l
In this example, we will do the synchronization of files from one remote host to another remote host. For this we have a playbook like below:
src: /var/tmp/sync_folder dest: /var/tmp/ delegate_to: host-two
On the remote machine, we can cross-check to confirm the files have been transferred.
ls -l
ConclusionAs we saw, Ansible synchronize is powerful but easy to use the module, but we must also acknowledge that this is not the replacement of rsync in Linux systems. So keeping in mind, you must also remember all the limitations mentioned above in this article to avoid unexpected outcomes. So learn it first and then use it carefully.
Recommended ArticlesThis is a guide to Ansible Synchronize. Here we also discuss the Introduction and how does ansible synchronize works along with examples and its code implementation. You may also have a look at the following articles to learn more –
Update the detailed information about Learn How Untar Works In Ansible With Examples on the Kientrucdochoi.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!