Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Notes on ansible-related commands

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Commonly used ansible commands, memos.

1. Modify the / etc/ansible/hosts file to add the hosts you need to operate:

Vi / etc/ansible/hosts

[ywbhost]

192.16.1. [29:52] ansible_ssh_uer= "root" ansible_ssh_pass= "xxxxxx"

Execute the shell command:

Ansible ywbhost-m shell-a "/ tmp/setdns.sh"

Third, copy files

Copy the file to the remote host copy:

Ansible ywbhost-m copy-a "src=/etc/ansible/ywb/setdns.sh dest=/tmp/setdns.sh mode=755"

Copy files from the remote host to the local machine, fetch:

Ansible ywbhost-m fetch-a "src=/tmp/setdns.sh dest=/tmp/setdns.sh mode=755"

IV. Text manipulation:

1. Add a line at the end of the text

Ansible ywbhost-m lineinfile-a "dest=/etc/chrony.conf line='server 192.168.1.33 iburst'"

2. Replace one line

Ansible all-m lineinfile-a "dest=/root/test.txt regexp='bbb' line='bbbbbbb'"

3. Insert a row before a line:

Ansible all-m lineinfile-a "dest=/root/test.txt insertbefore='aa (. *) 'line='eeee'"

4. Insert a row after a line, insertafter

Ansible all-m lineinfile-a "dest=/root/test.txt insertafter='aa (. *) 'line='eeee'"

5. Delete a line:

Ansible all-m lineinfile-a "dest=/root/test.txt regexp='aa (. *) 'state=absent"

6. Replace or add a line: ansible all-m lineinfile-a "dest=/root/test.txt regexp='he (. *) 'line='lllll' state=present"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report