Hot answers tagged

35

In order to strip the bar-version-someFirstLevelFolder you need to use the --strip-components=1 option in tar. So your playbook should look like - name: Extract archive unarchive: src: file.tar.gz dest: /foo/bar extra_opts: [--strip-components=1]


34

From the documentation: src, path of the file to link to (applies only to state=link). Will accept absolute, relative and nonexisting paths. Relative paths are not expanded. You need to use src and dest when using state=link, not path. You also need to invert your source and destination, which appear to be the wrong way around (assuming that you really ...


24

Starting from v2.0 Ansible supports variable substitution in task/handler names: https://github.com/ansible/ansible/issues/10347, so these examples will work as expected: - name: upgrade software on {{inventory_hostname}} - name: current host is {{ansible_hostname}}


23

ansible -m debug -a "var=hostvars[inventory_hostname]" seems to work. Valid variable sources (host_vars, group_vars, _meta in a dynamic inventory, etc.) are all taken into account. With dynamic inventory script hosts.sh: #!/bin/sh if test "$1" = "--host"; then echo {} else cat <<EOF { "ungrouped": [ "x.example.com", "y.example.com" ...


12

It seems like copy parameter for unarchive module is what tripped you up. http://docs.ansible.com/unarchive_module.html states: -If copy=yes (default), local path to archive file to copy to the target server; can be absolute or relative. -If copy=no, path on the target server to existing archive file to unpack. In essence get_url downloaded your file to ...


10

Since @William still got it wrong (!) here we go: The format of lines in /etc/hosts is address first and name(s) second 0.0.0.0 node1 0.0.0.0 node2 192.168.1.1 myroutermaybe 8.8.8.8 googledns # in case DNS doesn't work for DNS??? 127.0.0.1 localhost or where several names map to the same address 0.0.0.0 node1 node2 node3 stitch626 ADDED, thanks to ...


8

I suppose there's no easy way for that. And register with with_items loop just puts all results of them into an array variable.results. Try the following tasks: tasks: - name: Determine GIDs shell: "getent group {{ item }} | cut -d : -f 3" register: gids changed_when: false with_items: - syslog - utmp - ...


8

I would recommend pip: sudo pip install 'ansible==2.0.0.1' More information on ansible[1] and pip[2] documentation. And if you want to have more than one installed version, just use create virtualenv: virtualenv .env source .env/bin/activate pip install 'ansible==2.2.0.0' and only this terminal will use this specific version of Ansible. Then repeat the ...


7

Ask the program that produces those colors to stop, or remove those colors yourself: sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" ^I have this in an executable named uncolor so that I can do: aProgramThatWontStopColoring | uncolor


7

- name: install mssql-server repo (CentOS, RedHat) get_url: url: "{{ centos_repo_url }}" dest: /etc/yum.repos.d/mssql-server.repo when: ansible_distribution in ['CentOS', 'RedHat'] - name: install mssql-server repo (Ubuntu) get_url: url: "{{ ubuntu_repo_url }}" dest: /etc/apt/sources.list.d/mssql-server.list when: ...


7

You'll probably want to tell ansible where the hosts file is in ansible.cfg, e.g. [defaults] inventory=inventory assuming inventory is actually your inventory file.


7

Apparently unattended-upgrades is run from one of the systemd units apt-daily.service / apt-daily-upgrade.service. (These in turn are triggered by systemd .timer units, with the same names). You could try to wait for the systemd units as follows: systemd-run --property="After=apt-daily.service apt-daily-upgrade.service" --wait /bin/true This is ...


7

Maintaining a meta-package-manager seems to me to be a Sisyphean task, as someone would have to be maintaining some sort of "apache2" in Debian-likes is "httpd" in RHEL-likes (et cetera) Rosetta Stone. However, there is a pacman module for Ansible which is purpose-made for using Ansible (the disto-agnostic management tool you're looking for) to manage ...


7

You're passing the parameter in double quotes. $HOME is expanded by the shell on your local machine, ansible doesn't even get to see it. If you use single quotes instead, you should be able to see a difference. (You would also have noticed if the path didn't exist on the remote machine.)


6

There are a couple of options regarding error handling in Ansible. You could use ignore_errors: yes attribute on your task. If you don't want to ignore all errors, you can specify what exactly constitutes an error using something like: - name: task name module: arguments ... register: out failed_when: 'error message' in out.stderr If you want to add ...


5

First: you need to indent password: in your playbook, because you want it to be a variable: vars: password: hashed_password If it's not indented then Ansible considers it a play parameter and throws an error because password is not. Second: unless you are setting the password for a user on OSX, you need to provide a hashed value of a password. Follow ...


4

You can use inventory_hostname magic variables in this case. { "atlanta" : { "hosts" : [ "host1", "host4", "host5" ], "vars" : { "ansible_ssh_host" : "{{inventory_hostname}}.example.com", "b" : false } }


4

You can use debug to dump the variable: - name: this command prints FAILED when it fails command: /usr/bin/example-command -x -y -z register: command_result failed_when: "'FAILED' in command_result.stderr" - name: dump command_result debug: var=command_result This will output something like: TASK: [dump command_result] *****************************...


4

Refer to https://docs.ansible.com/ansible/yum_repository_module.html Your code should be - hosts: all # define variables. vars: epelReleaseMajorVersion: 7 epelReleaseMinorVersion: 8 tasks: - name: add epel repo yum_repository: name: epel_repo description: EPEL YUM repo baseurl: http://dl.fedoraproject.org/...


4

you should configure admin as a remote_user, not become_user. The become_user option sets to which user you would su to execute certain task. In other words, your playbook should look like: --- - hosts: somehosts remote_user: admin roles: .... #tasks file --- # tasks file for test - name: Change dns become: yes replace: dest: /etc/resolv....


4

So this appears to be a problem that showed up after CentOS 6.5. There's this customer portal topic on it, titled: iptables failed to start in Red Hat Enterprise Linux 6.6 and above versions of minimal installation.. The direct problem is the absence of the /etc/sysconfig/ip* files that the iptables service requires to start. You can force the creation of ...


4

UPDATE: should be fixed in the next release (1.18.8). https://etckeeper.branchable.com/todo/requires___96__user.email__96___be_set_under_undocumented_circumstances/ After hitting this a couple of times, I felt I needed to look at the source code. git absolutely requires an "email address" for its commits. Without one, it will refuse to make a commit. git ...


4

To avoid matching in a comment, anchor your regexp to the beginning of the line: - { inserts: '^\[database\]', lines: 'rpc_backend = rabbit' }


4

SSHpass was working fine, but the alpine container python:3.6-alpine doesn't have openssh installed. This errormessage is confusing as it doesn't mention that the ssh component is failing. This can be fixed by running apk add --update openssh. This was resolved by changing the line in the Dockerfile from RUN apk add --update --no-cache sshpass to RUN apk ...


4

What precisely is going on when one "passes a heredoc as a file"? You aren't. Here-documents provide standard input, like a pipe. Your example awk '{ ... }' <<EOF foo bar baz EOF is exactly equivalent to echo foo bar baz | awk '{ ... }' awk, cat, and ruby all read from standard input if they aren't given a filename to read from on the command line....


4

As is typical with some of the modules in ansible you have to install certain Python modules on the remote server's side. https://github.com/ansible/ansible/issues/21416 You can use the pip module to facilitate this through your ansible playbook like so: - name install pexpect pip: name: pexpect become: yes Your distro may have these available as ...


4

From the Ansible Docs: - name: Install a list of packages apt: name: "{{ packages }}" vars: packages: - foo - foo-tools - name: Download foo.conf get_url: url: http://example.com/path/file.conf dest: /etc/foo.conf mode: 0440 Since this is written in Ansible Playbook format. You would need to write it to a yaml file, and ...


4

I do not think there is a big problem with 20 lines, as a shell script for an individual machine or two. That is a good thing to have. That said, your script is not idempotent. For example it uses apt-get upgrade foo, which can perform changes even if the script has already been run on this system. I do not think it worth using apt-get upgrade foo. That ...


4

For a user to use /apps/ansible/ansible.cfg you can either Link ~/.ansible.cfg (in the home directory) to /apps/ansible/ansible.cfg, or Set ANSIBLE_CONFIG (environment variable) to /apps/ansible/ansible.cfg Refer to details.


Only top voted, non community-wiki answers of a minimum length are eligible