- name: Go to the folder
  command: chdir=/opt/tools/temp
运行我的剧本时,我得到:
TASK: [Go to the folder] ***************************** 
failed: [host] => {"failed": true, "rc": 256}
msg: no command given
任何帮助深表感谢。
- name: Go to the folder
  command: chdir=/opt/tools/temp
运行我的剧本时,我得到:
TASK: [Go to the folder] ***************************** 
failed: [host] => {"failed": true, "rc": 256}
msg: no command given
任何帮助深表感谢。
command: ls chdir=/path/to/directory
                Answers:
Ansible中没有当前目录的概念。您可以为特定任务指定当前目录,就像在剧本中一样。唯一缺少的部分是要执行的实际命令。尝试这个:
- name: Go to the folder and execute command
  command: chdir=/opt/tools/temp ls
"There's no concept of current directory in Ansible"我认为事实不再如此,很多任务现在都采用相对路径,例如npm composer bower等等
                    当我试图弄清楚为什么chdir当我不得不恢复到Ansible 1.9时,为什么“ shell”不尊重我的输入内容时,这个问题就出现了。因此,我将发布解决方案。
我有
- name: task name
  shell:
    cmd: touch foobar
    creates: foobar
    chdir: /usr/lib/foobar
它适用于Ansible> 2,但对于1.9,我不得不将其更改为。
- name: task name
  shell: touch foobar
  args:
    creates: foobar
    chdir: /usr/lib/foobar
只是想分享。
如果您需要登录控制台(例如捆绑程序),则必须执行以下命令。
command: bash -lc "cd /path/to/folder && bundle install"
command: bash -lc "cd /var/www/ && /usr/local/bin/composer install"
                    working_dir指定相对的作曲者路径