Use Ansible-Ad_Hoc interim order

Use Ad_Hoc interim order

  • 1, usage scenarios:
    • All temporary access to information can be used, such as health checks before the holiday, temporary update the configuration file.
  • 2, Usage:
    • ansible -i host -m module option
  • 3, commonly used command options:
    • -v output more detailed execution process information, -vvv execution process all the information available
    • -i PATH, specify the inventory information
    • -f number of concurrent threads, thread default 5
    • -m NAME, specify the module to be executed
    • -a 'ARGUMENTS', parameter module
    • -k authentication password (user password execute) (ansible execute ssh if not certified, you can directly use the -k option to execute an interactive command to enter a password)
    • -K user's password (the password is switched to the specified user)
    • the equivalent of sudo -s command linux system.
    • -U Use sudo, sudo command corresponding to a linux system (this option is switched to a user to perform specified)
    • --list-hosts, in line with the conditions listed in the list of hosts
  • 4, using common modules
    • (1) All the listed modules: ansible-doc -l
    • (2)command 模块(不执行"<", ">", "|", "&"):ansible web -m command -a 'ls' -s -k
    •  

       

    • (3)shell  raw 模块(raw没有chdir  creates  removes 参数):ansible all -m shell -a 'chdir=/tmp touch f2' -s -k 
    • (4) script module (complex processing command, the principle is to perform a local operation script): ansible Web -m -a Script ' u.sh ' -s -k
    •  

       

    • (5) copy module (copy module to the remote host): ansible Copy All -m -a '= the src / the root / dest = Resolv.conf / Resolv.conf' -s -k
    •  

       

    • (6) lineinfile | replace module (modify configuration files):
    • ansible web -m lineinfile -a 'path=/etc/sysconfig/network-scripts/ifcfg-eth0 regexp="^ONBOOT" line="ONBOOT=\"no\""' -s -k
    • ansible web -m replace -a 'path=/etc/sysconfig/network-scripts/ifcfg-eth0 regexp="^(ONBOOT=).*" replace="\1\"yes\""' -s -k 
    • (7) passing Yue well (note that a user specified storage path and the male Yue): ansible myDB authorized_key -m -a "User hraa0101 exclusive = = = Key to true to true manage_dir = '$ (</home/hraa0101/.ssh/id_rsa. pub) ' "-k -v

 

summary

  • 1, ansible using some functions, such as specifying the number of threads open, specify the user to execute a command, etc., you can use the command-line option is specified, the relevant information can be written into the configuration file, the final can achieve this functionality.
  • 2, dealing with complex commands can be used in conjunction with the script, especially script Three Musketeers, with the flexibility to learn to use.
  • 3, the actual implementation process, you can specify the authentication password information in the Inventory file. For example ansible_ssh_user, ansible_ssh_pass, ansible_su_pass, ansible_become_pass and so on.

Guess you like

Origin www.cnblogs.com/hraa0101/p/11927022.html