ansible learning

First, install ansible

git clone https://github.com/ansible/ansible.git

cd ansible

python3 setup.py install

sudo mkdir /etc/ansible

sudo chmod 777 /etc/ansible

cp -r examples/* /etc/ansible

Second, ping test module, ansible the ping protocol using ssh

 vim /etc/ansible/hosts

    [hostname1]
    xxx.xxx.202.1

ansible all -m ping
[WARNING]: Ansible is being run in a world writable directory (/private/etc/ansible), ignoring it as an
ansible.cfg source. For more information see
https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir

[WARNING]: Unable to parse the plugin filter file /etc/ansible/plugin_filters.yml as module_blacklist is
not a list. Skipping.

114.115.202.1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
    "unreachable": true

   Ansible will be like trying to use SSH as your current user name to connect to your remote machine. To override the remote user name, simply use '-u' option. If you want to visit sudo mode, where there are signs (flags) to achieve:

  ansible all -m ping -u root

 Third, the understanding of the configuration file

ansible.cfg vim 

#host_key_checking = False recommended uncommented, or the first connection asks too much trouble 

for example,
at The Authenticity of Host 'xxx (xxx)' CAN BE not the ESTABLISHED.
ECDSA Key Fingerprint IS SHA256: xxxx
Are you the Sure you want to continue connecting (yes / no )? yes

  Ansible There are many configuration parameters, the following are a few default configuration parameters:

inventory = /etc/ansible/hosts
library = /usr/share/my_modules/ forks = 5 sudo_user = root remote_port = 22 host_key_checking = False timeout = 20 log_path = /var/log/ansible.log 

inventory: This parameter indicates the location of inventory files, resource inventory (inventory) is Ansible need to connect some of the host list management.
library: Ansible all operations are performed using the module achieve, this parameter is the library catalog Ansible module pointing storage.
forks: Ansible to have settings By default the maximum number of processes simultaneously, the default five processes in parallel. In particular need to set the number, it may be determined according to the performance of the control terminal and the number of managed nodes.
sudo_user: Set the default user to execute a command, you can reset this parameter in the playbook.
remote_port: Specifies the connection port management managed node, the default is 22, unless a special SSH port settings, you will not need to modify this parameter.
host_key_checking: Set whether to check the SSH host key. It can be set to True or False. That ssh host verification again.
timeout: SSH connection set timeout interval, in seconds.
log_path: Ansible default does not log, if you want to output Ansible system of records to a log file, you need to set log_path. It is noted that the module will call is managed node (r) syslog recorded, the user needs to have performed Ansible permission to write to the log.

 

Guess you like

Origin www.cnblogs.com/agang-php/p/11568727.html