Filtered: ansible centos2.jm -m setup -a "filter=*dist*" | less -MN.Facts may be filtered using the setup module ad-hoc by passing a value for the filter param.Ansible facts are properties and info about remote systems.The script module allows you to run entire shell scripts rather than single commands.Īnsible localhost -a "touch /tmp/test1 " # Same command, but skips if file existsĪnsible localhost -a "touch /tmp/test1 creates=/tmp/test1 " # Delete the fileĪnsible localhost -a "rm -f /tmp/test1 removes=/tmp/test1 " # Shell module for env variable and output redirectionĪnsible localhost -m shell -a "echo $PATH > /tmp/file1 " Collecting system information.It's best to use modules that do what you need so you don't need to define success criteria for raw commands.The shell module might be preferred for input/output redirection, env variables, and other shell features not supported by the command module.The shell command is almost identical, except the commands are run in a shell environment.It's best practice to use this module unless you require shell features. The command module is the default with ansible ad-hoc when no module is specified.The shell and command modules allow you to run raw commands on a target host.You can also use the ansible-doc command.You can visit and use ctrl + F to search for keywords such as "Cisco IOS.".Example modules include: ping, setup, yum, service, and copy.Most modules take key=value arguments delimited by whitespace (there are exceptions).Modules are discrete units of code that can be used from the CLI or in a playbook task.Example to remove software: ansible centos2.jm -b -m yum -a "name=elinks state=absent".Example to install software: ansible centos2.jm -b -m yum -a "name=elinks state=installed".-b = become, which by default becomes root.Syntax for ad hoc command: ansible $host -m $module -a $arg1 -f $num_forks.Playbooks are comparable to bash scripts.Ansible ad hoc commands are comparable to bash commands.You can then execute the command by referencing a host or a group: ansible routers -m pingīack to table of contents Understanding ansible ad hoc The ansible command You can use a pattern such as for ansible to expand out # Example groups You can create groups of hosts and specify hosts by name or IP address. The default file has a lot of examples of what you can do.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |