3.3 使用template模块调用j2文件使用for循环: 创建jinja关于for的文件: [root@master ansible]# cat roles/temp/templates/test_for.j2 {%foriinrange(1,10) %} test{{ i }} {% endfor %} 1. 2. 3. 4. [root@master ansible]# cat roles/temp/tasks/main.yaml -name: copy config...
- name: Write the apache config file ansible.builtin.template: src: /srv/httpd.j2 dest: /etc/httpd.conf notify: - Restart apache - name: Ensure apache is running ansible.builtin.service: name: httpd state: started handlers: - name: Restart apache ansible.builtin.service: name: httpd sta...
Iffile, even with other options (such asmode), the file will be modified if it exists but will NOT be created if it does not exist. Set totouchor use theansible.builtin.copyoransible.builtin.templatemodule if you want to create the file if it does not exist. ...
template module– Template a file out to a target host unarchive module– Unpacks an archive after (optionally) copying it from the local machine uri module– Interacts with webservices user module– Manage user accounts validate_argument_spec module– Validate role argument specs. ...
ansible.builtin.yum:name:httpdstate:latest-name:编写apache配置文件 ansible.builtin.template:src:/srv/httpd.j2dest:/etc/httpd.conf-name:更新数据库服务器hosts:databasesremote_user:roottasks:-name:postgresql是最新版本 ansible.builtin.yum:name:postgresqlstate:latest-name:启动postgresql ...
官方文档:https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_repository_module.html 参数解释: 代码语言:javascript 复制 name :相当于.repo文件定义中括号的[仓库ID] baseurl :相当于.repo文件中baseurl description :相当于.repo文件中的name file :相当于.repo文件的名称,不使用时默认以...
官网地址: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html 常用参数: 参数 选项/默认值 说明 path/dest 目标文件绝对路径+文件名,必须参数 line 替换/插入的内容 regexp 待匹配内容 insertbefore 匹配行前面插入 insertafter 匹配行面插入 state present / absent 删除匹...
-name:Install NGINXansible.builtin.include_role:name:nginxinc.nginx Git To pull the latest edge commit of the role from GitHub, use: git clone https://github.com/nginxinc/ansible-role-nginx.git To use the role, include the following task in your playbook: ...
templates/:template模块查找所需要模板文件的目录 tasks/:定义task,role的基本元素,至少应该包含一个名为main.yml的文件;其它的文件需要在 此文件中通过include进行包含 handlers/:至少应该包含一个名为main.yml的文件;此目录下的其它的文件需要在此文件中通过 ...
{ ansible_nodename }}"check_implicit_admin:Trueloop: -127.0.0.1-::1-localhost-name:Create .my.cnfansible.builtin.template:src:"client.my.cnf.j2"dest:"/root/.my.cnf"owner:rootgroup:rootmode:0600-name:mysql_secure_installation Delete anonymous MySQL usercommunity.mysql.mysql_user:name:""...