Ansible:如何在Ansible Playbook中更改active directory?
当我运行我的剧本时,我得到:Ansible:如何在Ansible Playbook中更改active directory?,ansible,Ansible,当我运行我的剧本时,我得到: - name: Go to the folder command: chdir=/opt/tools/temp 非常感谢您的帮助。Ansible中没有当前目录的概念。您可以为特定任务指定当前目录,就像您在playbook中所做的那样。唯一缺少的部分是要执行的实际命令。试试这个: TASK: [Go to the folder] ***************************** failed: [host] => {"failed": true
- name: Go to the folder
command: chdir=/opt/tools/temp
非常感谢您的帮助。Ansible中没有当前目录的概念。您可以为特定任务指定当前目录,就像您在playbook中所做的那样。唯一缺少的部分是要执行的实际命令。试试这个:
TASK: [Go to the folder] *****************************
failed: [host] => {"failed": true, "rc": 256}
msg: no command given
如果您需要一个登录控制台(如bundler),那么您必须执行如下命令
command:bash-lc“cd/path/to/folder&&bundle安装”
当我试图找出为什么“shell”不尊重我的chdir
条目,而我不得不恢复到Ansible 1.9时,这个问题出现在结果中。因此,我将发布我的解决方案
我有
它在Ansible>2时工作,但对于1.9,我必须将其更改为
- name: task name
shell:
cmd: touch foobar
creates: foobar
chdir: /usr/lib/foobar
只想共享。在使用ansible with运行命令之前,您可以更改为目录 以下是我刚刚设置的一个示例:
- name: task name
shell: touch foobar
args:
creates: foobar
chdir: /usr/lib/foobar
更改活动目录的具体操作是什么?chdir也是command的一个属性。您可以使用do命令,还可以声明chdir
命令:ls chdir=/path/to/directory
这与Microsoft的ActiveDirectory无关,是吗?这也是与composer一起使用的命令(如果composer模块没有实现):命令:bash-lc“cd/var/www/&/usr/local/bin/composer安装”
现在,您可以使用用户工作目录
来指定编写器路径相对性,以便能够在特定目录中运行所有剧本“Ansible中没有当前目录的概念”
我认为这不再是真的,现在很多任务都采用相对路径,例如npm
composer
bower
等
- name: task name
shell: touch foobar
args:
creates: foobar
chdir: /usr/lib/foobar
- name: Run a pipenv install
environment:
LANG: "en_GB.UTF-8"
command: "pipenv install --dev"
args:
chdir: "{{ dir }}/proj"