我在ansible中有一个角色,在命令行工作,但不是通过awx。
在这方面,作用:
- name: Enable persistent logging
ansible.builtin.lineinfile:
path: /etc/systemd/journald.conf
regexp: '^#Storage'
line: Storage=persistent
- name: Check directory
ansible.builtin.stat:
path: "{{ journal_dir }}"
register: journaldir
- block:
- name: Create directory
ansible.builtin.file:
path: "{{ journal_dir }}"
state: directory
mode: '0755'
- name: Enable systemd-tmpfiles folder
ansible.builtin.command: /bin/systemd-tmpfiles --create --prefix {{ journal_dir }}
check_mode: no
notify:
- restart systemd-journald
when: journaldir.stat.exists == false and ansible_distribution_major_version >= '7'在这里,通知代码:
- name: restart systemd-journald
ansible.builtin.service:
name: systemd-journald
state: restarted{ journal_dir } is /var/log/日志
当我在我的终端上运行剧本时,我没有问题,但是当我使用awx运行它时,我仍然有以下错误:
TASK [journalctl : Enable systemd-tmpfiles folder] *****************************
fatal: [server]: FAILED! => {"changed": false, "msg": "no command given", "rc": 256}我也用shell模块做过测试,这是相同的行为。
我不明白为什么。
谢谢你的帮助。
发布于 2022-10-31 16:33:07
对于这个问题,我似乎使用了ansible的旧版本,所以我不得不删除命令模块的fqcn。
它的工作方式如下:
- name: Enable systemd-tmpfiles folder
command: /bin/systemd-tmpfiles --create --prefix {{ journal_dir }}
notify:
- restart systemd-journald我通过命令行的不可用版本是2.9.27,awx的ansible版本是2.9.14。
在这里找到了解决方案:Ansible cant run any command or shell
https://stackoverflow.com/questions/74262027
复制相似问题