Homestead.yaml Shell provisioner `args` must be a string or array - laravel

I cannot run vagrant due to this error. I've posted my homestead.yaml code image.

Per your screenshot it looks like the last line of your yaml file is not correctly indented (you have extra space before value). It must be
variables:
- key: APP_ENV
value: local

Related

Line not updating in a file using win_lineinfile

I'm trying to update an appsettings.json file on each one of my nodes. When I run my playbook, I'm getting a changed state for all my nodes but when I check the node I don't see any changes to the line. I'm also trying to update the string with the hostname but that doesn't seem to be working very well.
Here is an example of what I'm trying to do:
- name: Replace line in appsettings.json
win_lineinfile:
path: C:\BatchJobs\appsettings.json
regex: '"SrcDir:"\s*:\s*"[^"]*",'
line: '"SrcDir:" "\\\\<ip-address>\\D$\\ETLs\\{{ansible_hostname}}\\",'
Here is a snippet of the appsettings:
},
"DirectorySettings": {
"FileSettingsConfigFile": "\\\\10.34.0.202\\D$\\Config\\<config>",
"SrcDir": "\\\\<ip-Address>\\D$\\ETLs\\ETL01\\",
"DestinationDir": "D:\\DestinationDir\\",
"ShipDir": "D:\\ShipDir\\",
"FailedDir": "\\\\10.34.0.202\\D$\\FailedDir\\",
"DBQueriesBaseFolder": "./config/JobQueries/",
"FileStatJobConfig": "./config/FileStat/"
The issue was because of the documentation: https://docs.ansible.com/ansible/latest/modules/win_lineinfile_module.html#examples
I was able to get it working by changing to:
- name: Replace line in appsettings.json
win_lineinfile:
path: C:\BatchJobs\appsettings.json
regexp: '"SrcDir:"\s*:\s*"[^"]*",'
line: '"SrcDir:" "\\\\<ip-address>\\D$\\ETLs\\{{ansible_hostname}}\\",'

Register a list of variables from file in ansible

I have a file /tmp/components_list with a content like this:
ComponentA: '1263'
ComponentB: '989'
ComponentC: '1354'
I want to register variables in ansible (without quotes), according to the content of file and use them in the yml code.
So, as a result I need something like that:
- name: Get variables from file
Some actions with a file /tmp/components_list
- name: Using these variables
shell: docker run --name component artifactory:5100/radware/Component:{{ComponentA}}
So it should be a number in the variable ComponentA.
How can I do it by using ansible? Thanks!
You can use include_vars statement, see also How to include vars file in a vars file with ansible?

Is it safe to edit /etc/sudoers with the Ansible "lineinfile" module?

I want to change sudo session timeout according to this answer. I can edit ordinary file:
lineinfile:
path: /etc/sudoers
regexp: ^Defaults env_reset
line: Defaults env_reset,timestamp_timeout=60
But in first line of my /etc/sudoers written: # This file MUST be edited with the 'visudo' command as root. How to deal with it?
P.S.
Despite the fact that the short answer is yes, one must read Konstantin Suvorov answer about right way to do it with lineinfile and very interesting techraf answer about possible pitfalls on this way
There's a safenet option for such cases: validate.
The validation command to run before copying into place. The path to the file to validate is passed in via '%s' which must be present as in the example below. The command is passed securely so shell features like expansion and pipes won't work.
If you look at the examples section of lineinfile module, you'll see exactly what you need:
# Validate the sudoers file before saving
- lineinfile:
path: /etc/sudoers
state: present
regexp: '^%ADMIN ALL='
line: '%ADMIN ALL=(ALL) NOPASSWD: ALL'
validate: '/usr/sbin/visudo -cf %s'
It's safe if you've tested the syntax to be correct.
The point of encouraging visudo is to prevent someone from locking themselves out from administering a system by creating an invalid /etc/sudoers, whether by a typo or a thinko.
When you're using Ansible to perform an edit, you can test the code performing that edit to do the right thing with your actual config files, environment, and version of sudo before you roll it out. Thus, the concerns about people making a typo or a syntax error by hand aren't immediately relevant.
While this answer defines things correctly and this one provides a mitigation to potential problems, let's look at your code.
You ask Ansible to (potentially) replace the line defined in the following way:
regexp: ^Defaults env_reset
This is clearly a bad practice and if repeated for a parameter other than Defaults in sudoers file, it is likely to cause a critical problem.
Generally Defaults is the configuration parameter and env_reset is one of possible values.
You cannot assume that the actual configuration file will always contain ^Defaults env_reset string.
If there was a different value set, the regexp wouldn't match and you'd end up adding a second line starting with Defaults.
So the proper way to use lineinfile is to use regexp argument to match only the configuration parameter, not its value. In your case:
regexp: ^Defaults
line: Defaults env_reset,timestamp_timeout
The other potential pitfall is that sudoers contain sections which should be written in proper order. If the file you modify does not contain the line specified by the regular expression, lineinfile will add a new line to the end of the file, where it might get ignored, or result in an error (but that should be discovered by validation), and most likely cause confusion if human looked at the file later. So it might be wise to specify insertafter or insertbefore.
I think what you are missing is that in order to edit /etc/sudoers you need sudo-access. To do this in Ansible, you just need to add the become flag.
name: Change Sudo Timeout
become: yes
lineinfile:
path: /etc/sudoers
regexp: ^Defaults env_reset
line: Defaults env_reset,timestamp_timeout=60
Instead of directly editing the /etc/sudoers you can place your desired setting into the /etc/sudoers.d directory like this:
- name: Change sudo session timeout
lineinfile:
dest: /etc/sudoers.d/ssh_session_timeout
line: 'Defaults env_reset,timestamp_timeout=60K'
create: yes
owner: root
group: root
mode: "0440"
state: present
validate: 'visudo -c -f %s'

Can 'extra_vars' receive multiple files?

According the Ansible documentation defining variables at runtime, it says I can load variables from a file.
ansible-playbook release.yml --extra-vars "#some_file"
However, in my case I have two files containing extra variables for my playbook invocation.
Concatenating them together is not an option because one is a secret file created and keyed using Vault. The other file is generated from an upstream process.
I have tried:
ansible-playbook release.yml --extra-vars "#some_file #some_other_file"
... but it didn't work. Upon invocation I get
ERROR: file could not read: some_file #some_other_file
so my guess is it takes everything after the first # symbols as the path of the file.
My questions is, can extra-vars accept multiple files?
It turns out I can use:
ansible-playbook release.yml --extra-vars=#some_file --extra-vars=#some_other_file
This does work for me. Please let me know if there is a better answer. Thanks.

Homestead "The shared folder guest path must be absolute"

I can‘t figure out how to solve this error when I run homestead up:
vm:
* The shared folder guest path must be absolute:
shell provisioner:
* Shell provisioner `args` must be a string or array.
* Shell provisioner `args` must be a string or array.
* Shell provisioner `args` must be a string or array.
My homestead.yaml file looks like
folders:
- map: ~/Code
to: /home/vagrant/Code/
I wrote the same paths like in the laracasts tutorial. What is wrong with the shared folder guest path "/home/vagrant/Code/"?
I have tried a lot of different ways to point to the directory but none of them worked out.
When I echo $PATH in the terminal I get /Users/username/.composer/vendor/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin
Thanks for help!
Change to: /home/vagrant/Code/ to to: /home/vagrant/Code
Also, I think it might have issues with ~/Code needing to be /Users/username/Code instead

Resources