![]() In this section, we walk you through how you can capture the output of a playbook in a variable and later display it.Īn ansible register is used for capturing a task’s output and save it a variable. There are instances, however, that you may be required to capture the output or results. Usually, Ansible playbooks are used to execute tasks on managed hosts without displaying the output on the command line. Variables to Retrieve the Results of Running Commands The command module retrieves the uptime of remote servers. name: Execute the Uptime command over Command module Example 1: Run a Command - name: Executing a command using the command moduleĮxample 2: Check Uptime of Remote Linux. The command is a passed the same way that you’d type in a Linux shell. One of the most commonly used modules, the command module takes the command name and later followed by a list of arguments. The module manages git checkouts of software repositories. This creates a compressed file in bz2 format from the /path/to/tecmint file. Example 3: Create a Archive File - name: Create a bz2 archive of /path/to/tecmint In the above play, the source file /path/to/tecmint is deleted after the archival is complete. This compresses the /path/to/tecmint_dir directory to /path/to/tecmint.tgzĮxample 2: Create a Archive File and Remove - name: Compress regular file /path/to/tecmint into /path/to/foo.gz and remove it Example 1: Create a Archive File - name: Compress directory /path/to/tecmint_dir/ into /path/to/tecmint.tgz After archival, the source file can later be deleted or removed using the statement remove=True. It assumes the compression source exists is present on the target destination. Archive ModuleĪn Archive module is used for the creation of a compressed archive of a single or multiple files. This adds the entry 10.200.50.51 to the /etc/hosts file. name: Add a line to a file if the file does not exist, without passing regexp The play above sets SELINUX value to disabled. name: Ensure SELinux is set to enforcing mode ![]() The lineinfile module is helpful when you want to change a single line in a file. The above play recursively deletes a directory. Example 4: Recursiverly Delete a Directory. This will create a directory in the /etc directory setting permissions to 0777. name: create a directory if it doesn’t exist The above play creates a file called nf in the /etc directory setting permissions to 0644. ![]() name: Change file ownership, group, and permissions Example 1: Perform Linux File Permissions. The file module is used to carry many file operations including creating files & directories, assigning file permissions, and setting symlinks. The permissions in the previous example can be represented as shown in the last line, The user is assigned read and write permissions, the group is assigned write permissions, and the rest of the world is assigned read permissions. Example 2: Copying Files from Local to Remote Linux. Permissions can also be represented using symbolic representation as shown in the last line. The playbook copies the config file nf from /etc/files/ directory to /srv/ directory as tecmint user with 0644 permissions. name: Copy file with owner and permissions Example 1: Copying Files from Local to Remote Linux. name: Restart network service for interface eth0Īs the name suggests, copy module copies files from one location on the remote machine to a different location on the same machine. name: Start service httpd, if not startedĮxample 3: Restarting a Network Interface enp2s0. The service module allows system administrators to start, stop, update, upgrade and reload services on the system. There is the apt module for APT package management for Debian based, the old yum module for YUM package management and dnf module associated with newer RHEL distributions.īelow are a few examples of how the modules can be used in a playbook: Example 1: Installing the Apache Webserver on RHEL 8 -Įxample 2: Installing the Apache Webserver on Debian 10.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |