“Ansible包管理模块”的版本间的差异
跳到导航
跳到搜索
(未显示同一用户的7个中间版本) | |||
第3行: | 第3行: | ||
<pre> | <pre> | ||
− | 参考最下面的官方文档 | + | 参考最下面的官方文档 告别是examples ,把 他们的 yml 内容放到你的 tasks 里面去就行了 |
cat /etc/ansible/hosts | cat /etc/ansible/hosts | ||
[tmp] | [tmp] | ||
第24行: | 第24行: | ||
ansible-playbook -C links.yml && ansible-playbook links.yml | ansible-playbook -C links.yml && ansible-playbook links.yml | ||
+ | |||
+ | 另外一个简单的playbook | ||
+ | cat kaling.yaml | ||
+ | - name: ins ng | ||
+ | hosts: kali | ||
+ | become: true | ||
+ | |||
+ | tasks: | ||
+ | - name: install ng | ||
+ | apt: | ||
+ | name: nginx | ||
+ | state: present | ||
+ | update_cache: true | ||
+ | - name: start ng | ||
+ | service: | ||
+ | name: | ||
+ | name: nginx | ||
+ | state: started | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | === Install ng on ubuntu vm=== | ||
+ | <pre> | ||
+ | cat ng.yml | ||
+ | - hosts: evan | ||
+ | become: yes | ||
+ | tasks: | ||
+ | |||
+ | - name: update | ||
+ | apt: update_cache=yes | ||
+ | |||
+ | - name: Install Nginx | ||
+ | apt: name=nginx state=latest | ||
+ | |||
+ | notify: | ||
+ | - restart nginx | ||
+ | |||
+ | handlers: | ||
+ | - name: restart nginx | ||
+ | service: name=nginx state=reloaded | ||
</pre> | </pre> | ||
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html | https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html | ||
+ | |||
+ | https://stackoverflow.com/questions/74869900/ansible-playbooks-install-a-list-of-apt-packages-from-a-file | ||
+ | |||
+ | [https://www.redhat.com/sysadmin/software-packages-ansible How to install software packages with an Ansible playbook] | ||
+ | |||
+ | |||
+ | |||
+ | [https://medium.com/@JleeCloudEngineer/how-to-install-nginx-using-ansible-playbook-on-ubuntu-vm-to-display-custom-html-page-fe8e7be4b1bc How to Install Nginx using Ansible Playbook on Ubuntu VM to display Custom HTML page] | ||
== 直接命令行== | == 直接命令行== | ||
第33行: | 第81行: | ||
ansible pi3 -m apt -a "name=links state=present" # install | ansible pi3 -m apt -a "name=links state=present" # install | ||
ansible pi3 -m apt -a "name=links state=absent" #remove | ansible pi3 -m apt -a "name=links state=absent" #remove | ||
+ | |||
+ | [https://stackoverflow.com/questions/41535838/how-to-run-apt-update-and-upgrade-via-ansible-shell How to run apt update and upgrade via Ansible shell] | ||
=yum module= | =yum module= | ||
− | + | ==playbook == | |
− | + | == == | |
+ | https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html#examples | ||
[[category:devops]][[category:ansible]] | [[category:devops]][[category:ansible]] |
2025年3月26日 (三) 14:59的最新版本
apt module
playbook
参考最下面的官方文档 告别是examples ,把 他们的 yml 内容放到你的 tasks 里面去就行了 cat /etc/ansible/hosts [tmp] 192.168.10.33 ansible_user=eva cat /etc/ansible/links.yml --- - hosts: tmp become: yes become_method: sudo remote_user: eva tasks: - name: Install links (state=present is optional) ansible.builtin.apt: name: links state: present ansible-playbook -C links.yml && ansible-playbook links.yml 另外一个简单的playbook cat kaling.yaml - name: ins ng hosts: kali become: true tasks: - name: install ng apt: name: nginx state: present update_cache: true - name: start ng service: name: name: nginx state: started
Install ng on ubuntu vm
cat ng.yml - hosts: evan become: yes tasks: - name: update apt: update_cache=yes - name: Install Nginx apt: name=nginx state=latest notify: - restart nginx handlers: - name: restart nginx service: name=nginx state=reloaded
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html
How to install software packages with an Ansible playbook
How to Install Nginx using Ansible Playbook on Ubuntu VM to display Custom HTML page
直接命令行
ansible用户 最好为root
ansible pi3 -m apt -a "name=links state=present" # install ansible pi3 -m apt -a "name=links state=absent" #remove
How to run apt update and upgrade via Ansible shell
yum module
playbook
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html#examples