$ ansible testserver -i inventory -m ping
The "ping": "pong" output text is specific to the ping module.
The ping module doesn’t do anything other than check that Ansible can start an SSH session with the servers.
ansible.cfg
ansible.cfg file, to set some defaults
Ansible looks for an ansible.cfg file in the following places, in this order:
* File specified by the ANSIBLE_CONFIG environment variable
* ./ansible.cfg (ansible.cfg in the current directory)
* ~/.ansible.cfg (.ansible.cfg in your home directory)
* /etc/ansible/ansible.cfg (Linux) or /usr/local/etc/ansible/ansible.cfg (*BSD)
We typically put ansible.cfg in the current directory, alongside our playbooks.
ansible.cfg
[defaults]
inventory = inventory/file_name.ini
host_key_checking = False
stdout_callback = yaml
callback_enabled = timer
$ ansible testserver -m ping
$ ansible testserver -m command -a uptime
When invoking this module, you also need to pass an argument to the module with the -a flag, which is the command to run.
The command module is the default module, so you can omit it:
$ ansible testserver -a uptime
$ ansible testserver -a "tail /var/log/dmesg"
If you need privileged access, pass in the -b or --become flag to tell Ansible to become the root user.
$ ansible testserver -b -a "tail /var/log/syslog"
$ ansible testserver -b -m package -a name=nginx
$ ansible-inventory --graph
Playbooks Are YAML
A valid JSON file is also a valid YAML file.
---
In Ansible playbooks it is customary to start with the three “-” (so that editors can pick up on this).
However, if you forget to put those three dashes at the top of your playbook files, Ansible won’t complain.
...
YAML files may end with three dots
If you forget to put those three dots at the end of your playbook files, Ansible won’t complain.
Comments start with a hashmark (#) and apply to the end of the line,
# This is a YAML comment
No comments:
Post a Comment