是否有可能在 Ansible 中取消设置事实(变量)?
以检查失败的方式取消设置is defined。
对于执行决策,我定期使用 来检查条件is defined。但是,可能需要在执行前取消设置这些设置,例如,如果通过 多次使用角色include_role或通过 多次使用任务include_tasks。
是否有特殊的语法,例如使用set_fact模块?
如果我理解正确的话,meta: clear_facts我会负责澄清所有事实,而不能仅限于个别事实。
是否可以集中定义任务选项以在不同的任务中重用它们?
我目前正在使用几个community.postgresql模块,例如postgresql_db和。我总是必须定义选项, , , ,但这些选项在整个执行过程中都是相同的,所以我想集中定义它们一次,然后只包含每个选项。postgresql_userpostgresql_privslogin_hostportlogin_userlogin_password
到目前为止,我的任务看起来像这样:
- name: Create database
community.postgresql.postgresql_db:
name: "{{ pg_db_name }}"
login_host: "{{ pg_host }}"
port: "{{ pg_port }}"
login_user: "{{ pg_admin.username }}"
login_password: "{{ pg_admin.password }}"
- name: Create database user
community.postgresql.postgresql_user:
name: "{{ pg_user.username }}"
password: "{{ pg_user.password }}"
login_host: "{{ pg_host }}"
port: "{{ pg_port }}"
login_user: "{{ pg_admin.username }}"
login_password: "{{ pg_admin.password }}"
- name: Set user privileges on database
community.postgresql.postgresql_privs:
database: …Run Code Online (Sandbox Code Playgroud) Ansible 是否有关于使用-(破折号)和_(下划线)的角色和集合的命名规则?
我注意到,从 2019 年左右开始,geerlingguy只使用下划线作为角色名称 (snake_case),但他的旧角色名称包含破折号 (kebab-case)。
\n对于Ansible Galaxy 中的一个角色,我遇到了以下注释:
\n\n\n注意:此角色已从 acme-sh 重命名为 acme_sh 以满足 Ansible Galaxy 要求。
\n
然后我查看了 Ansible Galaxy 文档,但只找到了命名空间的命名约定(限制),但没有找到角色或集合名称的命名约定(限制)。Ansible Galaxy 文档的创建角色页面上的示例也在名称中使用了破折号:test-role-1。
我知道所有 Ansible 内置模块仅使用下划线,因此严格意义上的 Snake_case (据我目前所见)。可能有一些模块允许在 kebab-case 中通过别名参数(例如apt),但很少。
\n在角色名称部分,我在第一个注释中找到了这个提示:
\n\n\n角色名称仅限于小写单词字符(即 az、0-9)和 \xe2\x80\x98_\xe2\x80\x99。
\n
然而,我不清楚这适用于哪些地方或操作,因为 Ansible Galaxy 中有相当多的角色名称中带有破折号,同样是一个ansible-galaxy role init my-super-role …