Invoked command cannot execute
paveldanilin opened this issue · 5 comments
Hi!
It seems there is a problem with a loss of command name in ProcessBuilder.
This code leads to an error "Invoked command cannot execute"
$a = new Ansible('ansible/project/test', '/usr/bin/ansible-playbook');
$a->playbook()->play('playbook.yml')->execute();
I guess the cause is an overriding of $arguments array in ProcessBuilder class.
- when we call Ansible::playbook(), there is a creation of AnsiblePlaybook instance that accepts as argument an instance of ProcessBuilder and we pass into constructor the playbookCommand
public function playbook(): AnsiblePlaybookInterface
{
return new AnsiblePlaybook(
$this->createProcess($this->playbookCommand)
);
}
- Now we have ProcessBuilder::arguments[0] = '/usr/bin/ansible-playbook';
- The overriding happens when we call AnsiblePlaybook::execute() , it calls protected method AbstractAnsibleCommand::runProcess:
$process = $this->processBuilder
->setArguments(
$this->prepareArguments()
)
->getProcess();
The prepareArguments method does not take into consideration that ProcessBuilder::arguments[0] already holds the value of command and spoils it.
In order to avoid a loss of command name, the ProcessBuilder::setArgument method should be changed to
public function setArguments(array $arguments): ProcessBuilderInterface
{
$prefix = $this->arguments[0] ?? null;
if ($prefix !== null) {
$this->arguments = array_merge([$prefix], $arguments);
} else {
$this->arguments = $arguments;
}
return $this;
}
thanks for the report! I'll have a look at the problem and get back to you shortly :-)
Kind regards,
Marc
Hello Pavel,
if you want, try the latest master - if you can confirm it's working, I'll tag a new release ;-)
And thanks again for reporting
Kind regards
Marc
Hello Marc,
Yes, now it works!
Your solution , which you have applied, is better for issue solving.
Will be released soon :-)